data test;
infile datalines dlm=',' dsd;
input Product $ Sale dollar6. ExchangeRate 4.2;
datalines;
Boot,29,761$,3.61
Men's Casual,67,242$,3.5
Sport Shoe,1,690$,3.48
;
run;
Perhaps this can help?
"Example 2: Reading Character Data That Contains Embedded Blanks"
Hi, thank you for your help, but this is not the same case.
Your data are totally messed up. data test; infile datalines ; input ; p=find(_infile_,','); product=substr(_infile_,1,p-1); _infile_=substr(_infile_,p+1); p=find(_infile_,'$'); sale=input(substr(_infile_,1,p),comma32.); _infile_=substr(_infile_,p+1); ratio=input(_infile_,comma32.); drop p; datalines; Boot,29,761$,3.61 Men's Casual,67,242$,3.5 Sport Shoe,1,690$,3.48 ; run;
So your source data is not formatted properly for anything. You cannot use comma as the delimiter and also have comma in the values. If your values contain the delimiter character then they need to be in quotes. Like this:
Boot,"29,761$",3.61
Men's Casual,"67,242$",3.5
Sport Shoe,"1,690$",3.48
But the presence of the $ after the value does present a method that might make it possible to read the data.
data fixed;
infile datalines dlm=',' dsd truncover column=cc;
length Product $20 Sale 8 ExchangeRate 8;
input product @ ;
start=cc ;
input @'$' @ ;
sale=input(substrn(_infile_,start,cc-start-1),comma32.);
input @cc+1 ExchangeRate ;
drop start;
datalines;
Boot,29,761$,3.61
Men's Casual,67,242$,3.5
Sport Shoe,1,690$,3.48
;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: