正文
- 附件以日文为例,是读入时的原始文件。
- 图1是Bug行在原文件中的字符串。
- 图2是Bug行在读入SAS后的字符串。Bug:最后一个字符没显示出来。
- 图3是经过统计输出csv内的字符串。Bug:1)字符串与原文件不符。2)猜测因为字符串Bug,导致csv文件打开时,不能有效判断逗号分隔符,数据列错位!
- 希望大神帮忙解决,不胜感激!!!下地跪谢!!!
图1
图2
图3
代码
- %let InPath=c:\users\****\documents\my sas files\appannie\;
- %let OutPath=c:\users\****\documents\my sas files\appannieresult\;
- %let tempfile=FileName;
- option noxwait;
- %sysexec cd &InPath.;
- %sysexec dir *.csv /b > &tempfile..txt;
- %let Code="utf-8";
- data FileName;
- infile "&InPath.&tempfile..txt" delimiter='09'x missover dsd lrecl=32767 ;
- informat InFileName $500. ;
- informat OutFileName $500. ;
- format InFileName $500. ;
- format OutFileName $500. ;
- input
- InFileName $
- @;
- OutFileName=substr(InFileName,48,length(InFileName)-48-26+1);
- output;
- if InFileName^= "&tempfile..txt";
- run;
- proc sql noprint;
- select count(InFileName) into : FileNumber
- from FileName;
- select InFileName into : InFileName1-:InFileName%left(&FileNumber.)
- from FileName;
- select OutFileName into : OutFileName1-:OutFileName%left(&FileNumber.)
- from FileName;
- quit;
- %macro ReadAnnie;
- %do i=1 %to &FileNumber.;
- data InFile&i.;
- infile "&InPath.&&InFileName&i."
- delimiter = ',' encoding=&Code
- MISSOVER DSD lrecl=32767 firstobs=2 ;
- informat Rank best32. ;
- informat Category $18. ;
- informat Store $11. ;
- informat Device $11. ;
- informat Type $4. ;
- informat Country $11. ;
- informat Period anydtdtm40. ;
- informat Version $3. ;
- informat App_ID best32. ;
- informat App_Name $39. ;
- informat Is_Unified $5. ;
- informat Value best32. ;
- informat Variation $6. ;
- informat Unit $9. ;
- informat Value_Type $8. ;
- informat AppURL $77. ;
- informat App_IAP $5. ;
- informat App_Category $19. ;
- informat App_Release_Date yymmdd10. ;
- informat Publisher_ID $16. ;
- informat Publisher_Name $23. ;
- informat Company_Name $23. ;
- informat Parent_Company_Name $23. ;
- informat App_Franchise $1. ;
- informat App_Franchise_ID $1. ;
- informat Company_ID $18. ;
- informat Parent_Company_ID $18. ;
- informat _HQ_Country $15. ;
- format Rank best12. ;
- format Category $18. ;
- format Store $11. ;
- format Device $11. ;
- format Type $4. ;
- format Country $11. ;
- format Period datetime. ;
- format Version $3. ;
- format App_ID best12. ;
- format App_Name $39. ;
- format Is_Unified $5. ;
- format Value best12. ;
- format Variation $6. ;
- format Unit $9. ;
- format Value_Type $8. ;
- format AppURL $77. ;
- format App_IAP $5. ;
- format App_Category $19. ;
- format App_Release_Date yymmdd10. ;
- format Publisher_ID $16. ;
- format Publisher_Name $23. ;
- format Company_Name $23. ;
- format Parent_Company_Name $23. ;
- format App_Franchise $1. ;
- format App_Franchise_ID $1. ;
- format Company_ID $18. ;
- format Parent_Company_ID $18. ;
- format _HQ_Country $15. ;
- input
- Rank
- @;
- if Rank^=. then do;
- input
- Category $
- Store $
- Device $
- Type $
- Country $
- Period
- Version $
- App_ID
- App_Name $
- Is_Unified $
- Value
- Variation $
- Unit $
- Value_Type $
- AppURL $
- App_IAP $
- App_Category $
- App_Release_Date
- Publisher_ID $
- Publisher_Name $
- Company_Name $
- Parent_Company_Name $
- App_Franchise $
- App_Franchise_ID $
- Company_ID $
- Parent_Company_ID $
- _HQ_Country $
- ;
- output;
- end;
- run;
- %end;
- %mend ReadAnnie;
- %ReadAnnie;
- %macro RankFiles;
- %do i=1 %to &FileNumber.;
- proc sql outobs=100;
- create table Downloads as
- select c.App_Name as App,c.Downloads,c.Parent_Company_Name as Parent_Company,d._HQ_Country as Country
- from(select a.App_Name,a.Downloads,b.Parent_Company_Name
- from (select App_Name,sum(Value) as Downloads
- from InFile&i
- where Unit="Downloads"
- group by App_Name) as a
- left join
- (select App_Name, max(Parent_Company_Name) as Parent_Company_Name
- from InFile&i
- where Parent_Company_Name^=""
- group by App_Name) as b
- on a.App_Name=b.App_Name) as c
- left join
- (select Parent_Company_Name,max(_HQ_Country) as _HQ_Country
- from InFile&i
- where _HQ_Country^="" and Parent_Company_Name^=""
- group by Parent_Company_Name) as d
- on c.Parent_Company_Name=d.Parent_Company_Name
- order by c.Downloads desc;
- quit;
- proc sql outobs=100;
- create table Revenue as
- select c.App_Name as App,c.Revenue,c.Parent_Company_Name as Parent_Company,d._HQ_Country as Country
- from(select a.App_Name,a.Revenue,b.Parent_Company_Name
- from (select App_Name,sum(Value) as Revenue
- from InFile&i
- where Unit="USD"
- group by App_Name) as a
- left join
- (select App_Name, max(Parent_Company_Name) as Parent_Company_Name
- from InFile&i
- where Parent_Company_Name^=""
- group by App_Name) as b
- on a.App_Name=b.App_Name) as c
- left join
- (select Parent_Company_Name,max(_HQ_Country) as _HQ_Country
- from InFile&i
- where _HQ_Country^="" and Parent_Company_Name^=""
- group by Parent_Company_Name) as d
- on c.Parent_Company_Name=d.Parent_Company_Name
- order by c.Revenue desc;
- quit;
- filename D "&OutPath.Downloads\Downloads_&&OutfileName&i...csv" encoding=&Code;
- filename R "&OutPath.Revenue\Revenue_&&OutfileName&i...csv" encoding=&Code;
- data _null_;
- file D delimiter=','DROPOVER lrecl=32767;
- if _n_ = 1 then /* write column names or labels */
- do;
- put
- "App"
- ','
- "Downloads"
- ','
- "Parent_Company"
- ','
- "Country"
- ;
- end;
- setWORK.Downloads end=EFIEOD;
- format App $39. ;
- format Downloads best12. ;
- format Parent_Company $23. ;
- format Country $15. ;
- do;
- EFIOUT + 1;
- AppChar=cats('"',App,'"');
- DownloadsChar=cats('"',Downloads,'"');
- ParentChar=cats('"',Parent_Company,'"');
- CountryChar=cats('"',Country,'"');
- put AppChar @;
- put DownloadsChar @;
- put ParentChar @;
- put CountryChar ;
- ;
- end;
- run;
- data _null_;
- file R delimiter=','DROPOVER lrecl=32767;
- if _n_ = 1 then /* write column names or labels */
- do;
- put
- "App"
- ','
- "Revenue"
- ','
- "Parent_Company"
- ','
- "Country"
- ;
- end;
- setWORK.REVENUE end=EFIEOD;
- do;
- EFIOUT + 1;
- AppChar=cats('"',App,'"');
- RevenueChar=cats('"',Revenue,'"');
- ParentChar=cats('"',Parent_Company,'"');
- CountryChar=cats('"',Country,'"');
- put AppChar @;
- put RevenueChar @;
- put ParentChar @;
- put CountryChar ;
- ;
- end;
- run;
- %end;
- %mend RankFiles;
- %RankFiles
复制代码
|