Hi Experts,
I have a sample dataset 'datain1', it contains a column 'Name' mixed with some various text separated by comma ' , '.
I would like to distribute the 'Name' text into different columns, result1-result3, based on the comma ' , '. Please check the result I am looking for is 'Dataout1'
Please let me know how to approach it. One thing I would like to point out that the 'Name' text includes different mixed names, sometime only have one name, sometime have three names, sometime have multiple names. Therefore, the 'result' columns should be based on the largest 'Name' numbers in the 'Name' text. The result3 column in the dataset is only the sample dataset I created.
Thanks.
data datain1; infile datalines delimiter='/'; input Name : $300. ; datalines; ACUTE OTITIS MEDIA,ASTIGMATISM, CONSTIPATION/ ACUTE URI, GERD/ BILATERAL. HYDRONEPHROSIS/ ; run; data dataout1; infile datalines delimiter='/'; input Name : $300. Result1 : $100. Result2 : $100. Result3 : $100.; datalines; ACUTE OTITIS MEDIA,ASTIGMATISM, CONSTIPATION/ACUTE OTITIS MEDIA/ASTIGMATISM/CONSTIPATION ACUTE URI, GERD/ACUTE URI/GERD/ / BILATERAL. HYDRONEPHROSIS/BILATERAL. HYDRONEPHROSIS/ / / ; run;
data datain1;
infile datalines delimiter='/';
input Name : $300. ;
length String1 String2 String3 $300;
array _string{*} String1 String2 String3;
end=countc(Name,',')+1;
do i = 1 to end;
_String[i] = scan(strip(Name),i,',');
end;
datalines;
ACUTE OTITIS MEDIA,ASTIGMATISM, CONSTIPATION/
ACUTE URI, GERD/
BILATERAL. HYDRONEPHROSIS/
;;;
run;
data datain1;
infile datalines delimiter='/';
input Name : $300. ;
length String1 String2 String3 $300;
array _string{*} String1 String2 String3;
end=countc(Name,',')+1;
do i = 1 to end;
_String[i] = scan(strip(Name),i,',');
end;
datalines;
ACUTE OTITIS MEDIA,ASTIGMATISM, CONSTIPATION/
ACUTE URI, GERD/
BILATERAL. HYDRONEPHROSIS/
;;;
run;
One more thing, how to change the 'end' number to the largest string number.
length String1 - String(end) $300; array _string{*} String1 - String(end); end=countc(name,',')+1; do i = 1 to end; _String[i] = scan(strip(name),i,','); end;
I tried, and it didn't work.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.