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
;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.