楼主: Silon.Jon
2872 2

[问答] <高手进>UTF8下SAS日韩字符有bug? [推广有奖]

  • 7关注
  • 0粉丝

本科生

43%

还不是VIP/贵宾

-

威望
0
论坛币
1281 个
通用积分
0.0002
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2606 点
帖子
86
精华
0
在线时间
67 小时
注册时间
2012-9-12
最后登录
2015-5-1

楼主
Silon.Jon 发表于 2015-5-1 16:35:50 |AI写论文
100论坛币
正文
  • 附件以日文为例,是读入时的原始文件。 App_Annie_Intelligence_Top_Unified_Apps_Charts_google-play_Japan_Games Casino_20.txt (433.35 KB)
  • 图1是Bug行在原文件中的字符串。
  • 图2是Bug行在读入SAS后的字符串。Bug:最后一个字符没显示出来。
  • 图3是经过统计输出csv内的字符串。Bug:1)字符串与原文件不符。2)猜测因为字符串Bug,导致csv文件打开时,不能有效判断逗号分隔符,数据列错位!
  • 希望大神帮忙解决,不胜感激!!!下地跪谢!!!


图1
Original.png

图2
Read.png

图3
Output.png

代码
  1. %let InPath=c:\users\****\documents\my sas files\appannie\;
  2. %let OutPath=c:\users\****\documents\my sas files\appannieresult\;
  3. %let tempfile=FileName;
  4. option noxwait;
  5. %sysexec cd &InPath.;
  6. %sysexec dir *.csv /b > &tempfile..txt;
  7. %let Code="utf-8";
  8. data FileName;
  9. infile "&InPath.&tempfile..txt" delimiter='09'x missover dsd lrecl=32767 ;
  10. informat InFileName $500. ;
  11. informat OutFileName $500. ;
  12. format InFileName $500. ;
  13. format OutFileName $500. ;
  14. input
  15.         InFileName $
  16.         @;
  17.     OutFileName=substr(InFileName,48,length(InFileName)-48-26+1);
  18.         output;
  19. if InFileName^= "&tempfile..txt";
  20. run;
  21. proc sql noprint;
  22.         select count(InFileName) into : FileNumber
  23.                 from FileName;
  24.         select InFileName into : InFileName1-:InFileName%left(&FileNumber.)
  25.                 from FileName;
  26.         select OutFileName into : OutFileName1-:OutFileName%left(&FileNumber.)
  27.                 from FileName;
  28. quit;
  29. %macro ReadAnnie;
  30.         %do i=1 %to &FileNumber.;
  31.                 data InFile&i.;
  32.                   infile "&InPath.&&InFileName&i."
  33.                   delimiter = ',' encoding=&Code
  34.                   MISSOVER DSD lrecl=32767 firstobs=2 ;
  35.                     informat Rank best32. ;
  36.                     informat Category $18. ;
  37.                     informat Store $11. ;
  38.                     informat Device $11. ;
  39.                     informat Type $4. ;
  40.                     informat Country $11. ;
  41.                     informat Period anydtdtm40. ;
  42.                     informat Version $3. ;
  43.                     informat App_ID best32. ;
  44.                     informat App_Name $39. ;
  45.                     informat Is_Unified $5. ;
  46.                     informat Value best32. ;
  47.                     informat Variation $6. ;
  48.                     informat Unit $9. ;
  49.                     informat Value_Type $8. ;
  50.                     informat AppURL $77. ;
  51.                     informat App_IAP $5. ;
  52.                     informat App_Category $19. ;
  53.                     informat App_Release_Date yymmdd10. ;
  54.                     informat Publisher_ID $16. ;
  55.                     informat Publisher_Name $23. ;
  56.                     informat Company_Name $23. ;
  57.                     informat Parent_Company_Name $23. ;
  58.                     informat App_Franchise $1. ;
  59.                     informat App_Franchise_ID $1. ;
  60.                     informat Company_ID $18. ;
  61.                     informat Parent_Company_ID $18. ;
  62.                     informat _HQ_Country $15. ;
  63.                     format Rank best12. ;
  64.                     format Category $18. ;
  65.                     format Store $11. ;
  66.                     format Device $11. ;
  67.                     format Type $4. ;
  68.                     format Country $11. ;
  69.                     format Period datetime. ;
  70.                     format Version $3. ;
  71.                     format App_ID best12. ;
  72.                     format App_Name $39. ;
  73.                     format Is_Unified $5. ;
  74.                     format Value best12. ;
  75.                     format Variation $6. ;
  76.                     format Unit $9. ;
  77.                     format Value_Type $8. ;
  78.                     format AppURL $77. ;
  79.                     format App_IAP $5. ;
  80.                     format App_Category $19. ;
  81.                     format App_Release_Date yymmdd10. ;
  82.                     format Publisher_ID $16. ;
  83.                     format Publisher_Name $23. ;
  84.                     format Company_Name $23. ;
  85.                     format Parent_Company_Name $23. ;
  86.                     format App_Franchise $1. ;
  87.                     format App_Franchise_ID $1. ;
  88.                     format Company_ID $18. ;
  89.                     format Parent_Company_ID $18. ;
  90.                     format _HQ_Country $15. ;
  91.                   input
  92.                     Rank
  93.                         @;
  94.                         if Rank^=. then do;
  95.                          input
  96.                       Category $
  97.                       Store $
  98.                       Device $
  99.                       Type $
  100.                       Country $
  101.                       Period
  102.                       Version $
  103.                       App_ID
  104.                       App_Name $
  105.                       Is_Unified $
  106.                       Value
  107.                       Variation $
  108.                       Unit $
  109.                       Value_Type $
  110.                       AppURL $
  111.                       App_IAP $
  112.                       App_Category $
  113.                       App_Release_Date
  114.                       Publisher_ID $
  115.                       Publisher_Name $
  116.                       Company_Name $
  117.                       Parent_Company_Name $
  118.                       App_Franchise $
  119.                       App_Franchise_ID $
  120.                       Company_ID $
  121.                       Parent_Company_ID $
  122.                       _HQ_Country $
  123.                       ;
  124.                          output;
  125.                         end;
  126.                 run;
  127.         %end;
  128. %mend ReadAnnie;
  129. %ReadAnnie;
  130. %macro RankFiles;
  131.         %do i=1 %to &FileNumber.;
  132.                 proc sql outobs=100;
  133.                   create table Downloads as
  134.                   select c.App_Name as App,c.Downloads,c.Parent_Company_Name as Parent_Company,d._HQ_Country as Country
  135.                     from(select a.App_Name,a.Downloads,b.Parent_Company_Name
  136.                                     from (select App_Name,sum(Value) as Downloads
  137.                                                     from InFile&i
  138.                                                         where Unit="Downloads"
  139.                                                         group by App_Name) as a
  140.                                         left join
  141.                                                   (select App_Name, max(Parent_Company_Name) as Parent_Company_Name
  142.                                                     from InFile&i
  143.                                                         where Parent_Company_Name^=""
  144.                             group by App_Name) as b
  145.                                         on a.App_Name=b.App_Name) as c
  146.                         left join
  147.                                   (select Parent_Company_Name,max(_HQ_Country) as _HQ_Country
  148.                                     from InFile&i
  149.                                         where _HQ_Country^="" and Parent_Company_Name^=""
  150.                     group by Parent_Company_Name) as d
  151.                         on c.Parent_Company_Name=d.Parent_Company_Name
  152.                         order by c.Downloads desc;
  153.                 quit;
  154.                 proc sql outobs=100;
  155.                   create table Revenue as
  156.                   select c.App_Name as App,c.Revenue,c.Parent_Company_Name as Parent_Company,d._HQ_Country as Country
  157.                     from(select a.App_Name,a.Revenue,b.Parent_Company_Name
  158.                                     from (select App_Name,sum(Value) as Revenue
  159.                                                     from InFile&i
  160.                                                         where Unit="USD"
  161.                                                         group by App_Name) as a
  162.                                         left join
  163.                                                   (select App_Name, max(Parent_Company_Name) as Parent_Company_Name
  164.                                                     from InFile&i
  165.                                                         where Parent_Company_Name^=""
  166.                             group by App_Name) as b
  167.                                         on a.App_Name=b.App_Name) as c
  168.                         left join
  169.                                   (select Parent_Company_Name,max(_HQ_Country) as _HQ_Country
  170.                                     from InFile&i
  171.                                         where _HQ_Country^="" and Parent_Company_Name^=""
  172.                     group by Parent_Company_Name) as d
  173.                         on c.Parent_Company_Name=d.Parent_Company_Name
  174.                         order by c.Revenue desc;
  175.                 quit;
  176.                 filename D "&OutPath.Downloads\Downloads_&&OutfileName&i...csv" encoding=&Code;
  177.                 filename R "&OutPath.Revenue\Revenue_&&OutfileName&i...csv" encoding=&Code;
  178.                 data _null_;
  179.                       file D delimiter=','  DROPOVER lrecl=32767;
  180.                       if _n_ = 1 then        /* write column names or labels */
  181.                        do;
  182.                          put
  183.                             "App"
  184.                          ','
  185.                             "Downloads"
  186.                          ','
  187.                             "Parent_Company"
  188.                          ','
  189.                             "Country"
  190.                          ;
  191.                        end;
  192.                      set  WORK.Downloads   end=EFIEOD;
  193.                          format App $39. ;
  194.                          format Downloads best12. ;
  195.                          format Parent_Company $23. ;
  196.                          format Country $15. ;
  197.                        do;
  198.                          EFIOUT + 1;
  199.                                  AppChar=cats('"',App,'"');
  200.                                  DownloadsChar=cats('"',Downloads,'"');
  201.                                  ParentChar=cats('"',Parent_Company,'"');
  202.                                  CountryChar=cats('"',Country,'"');
  203.                          put AppChar @;
  204.                          put DownloadsChar @;
  205.                          put ParentChar @;
  206.                          put CountryChar ;
  207.                          ;
  208.                        end;
  209.                       run;
  210.                 data _null_;
  211.                       file R delimiter=','  DROPOVER lrecl=32767;
  212.                       if _n_ = 1 then        /* write column names or labels */
  213.                        do;
  214.                          put
  215.                             "App"
  216.                          ','
  217.                             "Revenue"
  218.                          ','
  219.                             "Parent_Company"
  220.                          ','
  221.                             "Country"
  222.                          ;
  223.                        end;
  224.                      set  WORK.REVENUE   end=EFIEOD;
  225.                        do;
  226.                          EFIOUT + 1;
  227.                                  AppChar=cats('"',App,'"');
  228.                                  RevenueChar=cats('"',Revenue,'"');
  229.                                  ParentChar=cats('"',Parent_Company,'"');
  230.                                  CountryChar=cats('"',Country,'"');
  231.                          put AppChar @;
  232.                          put RevenueChar @;
  233.                          put ParentChar @;
  234.                          put CountryChar ;
  235.                          ;
  236.                        end;
  237.                       run;
  238.         %end;
  239. %mend RankFiles;
  240. %RankFiles
复制代码


关键词:bug franchise delimiter left join variation documents option files 日韩

沙发
Silon.Jon 发表于 2015-5-1 16:41:10
希望五一结束前有高手提点!

藤椅
stk 发表于 2015-5-4 09:07:16
将csv导入到excel,再导入到sas里试试

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-28 20:15