I've want to read var2 & var8 with (") in it.
I think dsd considering inverted comma as delimeter.
how can I read value ? please help !!
data ds2;
infile datalines dsd dlm="|" missover;
input (var1-var8) ($);
datalines;
2|"28 |4|||||29" |
run;
proc print data=ds2;
run;
My original code had an uncorrected oversight which I'll correct after posting this. The following will work with your tab delimited file:
data ds2; infile datalines dlm='09'x missover; input @; do while (index(_infile_,'0909'x) gt 0); _infile_=tranwrd(_infile_,'0909'x,'092E09'x); end; input (var1-var8) ($); datalines; 2 "28 4 29" ; run;
Art, CEO, AnalystFinder.com
data ds2;
infile datalines ;
input;
var1=scan(_infile_,1,'|','m');
var2=scan(_infile_,2,'|','m');
var3=scan(_infile_,3,'|','m');
var4=scan(_infile_,4,'|','m');
var5=scan(_infile_,5,'|','m');
var6=scan(_infile_,6,'|','m');
var7=scan(_infile_,7,'|','m');
var8=scan(_infile_,8,'|','m');
datalines;
2|"28 |4|||||29" |
run;
proc print data=ds2;
run;
If your data does not contain any Pipe characters as part of the actual data then you probably do not need DSD to read it.
If you data is not pipe delimited then you should indicate how the data is actually structured.
@ballardw the problem comes from the dual function of dsd; one needs dsd so that two or more successive delimiters are read as missing values. But then SAS also drops the quotes.
The following should work:
data ds2; infile datalines dsd dlm="|" missover; input @; _infile_=translate(_infile_,'~','"'); input (var1-var8) ($); array have(*) $ var1-var8; do i=1 to dim(have); have(i)=translate(have(i),'"','~'); end; datalines; 2|"28 |4|||||29" | run;
Art, CEO, AnalystFinder.com
Do you need to keep the quotation marks? If not, the array isn't needed as they could just be compressed rather than converted to a tilde.
Art, CEO, AnalystFinder.com
Then you could use:
data ds2;
infile datalines dlm="|" missover;
input @;
do while (index(_infile_,'||') gt 0);
_infile_=tranwrd(_infile_,"||","|.|");
end;
input (var1-var8) ($);
datalines;
2|"28 |4|||||29" |
;
run;
Art, CEO, AnalystFinder.com
My original code had an uncorrected oversight which I'll correct after posting this. The following will work with your tab delimited file:
data ds2; infile datalines dlm='09'x missover; input @; do while (index(_infile_,'0909'x) gt 0); _infile_=tranwrd(_infile_,'0909'x,'092E09'x); end; input (var1-var8) ($); datalines; 2 "28 4 29" ; run;
Art, CEO, AnalystFinder.com
@art297 I'm getting issue when my first column is blank...even though i've tried missover, truncover but issue still persist.
@atul_desh wrote:
@art297 I'm getting issue when my first column is blank...even though i've tried missover, truncover but issue still persist.
Add code to handle that case.
if _infile_=: '09'x then _infile_='.'||_infile_;
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.