Hello,
I am trying to read the pipe delimited file in which one of the character column is having long description starting from line1 to line3 or line1 to line2. I am unable to read this in sas dataset. Please help me to resolve the issue.
example:
1009|234|long description in comments
and need to be updated in the sas dataset.
Thank you for uploading data|264,00|345,09|address
1010|235|long description in comments
and need to be updated in the sas dataset|546.08|589|address
Thank you in advance.
You could read this with RECFM=N which means 'binary' so the datastep will continue reading across lines untill it reaches a delimiter.
In your example it does not work fully because there seems to be a delimiter missing at the end of the third row, after "adress". If that line would end with a delimiter this simple datastep would do the trick:
data want;
infile "c:\temp\file.txt" dlm="|" dsd recfm=N;
input f1 : $10. f2 : $10. comments : $500. ;
run;
with this result:
I had to read all your data as characters since the numbers are not using decimal comma and dots consistently. Is that voluntary ?
There is no delimiter at the end of the record.
options compress=yes; data have; infile cards length=len; input temp $varying2000. len; cards; 1009|234|long description in comments and need to be updated in the sas dataset. Thank you for uploading data|264,00|345,09|address 1010|235|long description in comments and need to be updated in the sas dataset|546.08|589|address ; data temp; set have; length x $ 8000; retain x; x=cats(x,temp); if countc(x,'|')=5 then do;output;call missing(x);end; drop temp; run; data want; set temp; a1=scan(x,1,'|'); a2=scan(x,2,'|'); a3=scan(x,3,'|'); a4=scan(x,4,'|'); a5=scan(x,5,'|'); a6=scan(x,6,'|'); drop x; run;
Here is an alternative way.
options compress=yes; data have; infile cards length=len; input temp $varying2000. len; if prxmatch('/^\d+\|\d+/',temp) then group+1; cards; 1009|234|long description in comments and need to be updated in the sas dataset. Thank you for uploading data|264,00|345,09|address 1010|235|long description in comments and need to be updated in the sas dataset|546.08|589|address ; data temp; length x $ 8000; do until(last.group); set have; by group; x=cats(x,temp); end; drop temp; run; data want; set temp; a1=scan(x,1,'|'); a2=scan(x,2,'|'); a3=scan(x,3,'|'); a4=scan(x,4,'|'); a5=scan(x,5,'|'); a6=scan(x,6,'|'); drop x; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.