Hello,
I'm having two single quote (') seprated by delimeter.
its is reading them as 1 and var3 is equal to "8" which should be var4 in second observation.
data ds1;
infile datalines dsd dlm='|';
input var1-var4;
datalines;
1|2|3|4|
9|'|'|8|
run;
proc print data=ds1;
run;
Also I don't want to "~" before variable because in actual case I don't which two consuctive variable will contain single quotation.
Actual text which I'm trying to import from unix contains 200 variable and that is tab delimited.. I've given above example of pipe delimited just to more readable.
Please help me out !!
Thanks
Atul Deshmukh
The behavior you are observing is the purpose of the DSD option as documented. When I removed the DSD option the data read as intended.
So if your input file never has null values then you can just drop the DSD option.
But if your input file has both null values (ie examples where two delimiters are right next to each other and it means there is value that empty) then you will need to process the data line before reading it.
So you could change the |'| into |"'"| so that SAS will see that the single quote is in fact a quoted string and so the DSD option will work.
input @;
do while (index(_infile_,"|'|"));
_infile_=tranwrd(_infile_,"|'|","|""'""|");
end;
input var1-var5;
Or if you never have actual quoted string values that would also require the DSD option then perhaps you can drop the DSD option from the INFILE and instead convert the || into |.| to indicate a missing value.
input @;
do while (index(_infile_,"||"));
_infile_=tranwrd(_infile_,"||","|.|");
end;
input var1-var5;
@atul_desh wrote:
But my actual file is not pipe delimited it is tab delimeted... Here I've given example of pipe delimited just to get more understand.
So in the fix use tabs instead of pipe character. The hex code for a tab is '09'x.
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.