I have a list of user entered data from xls which I have read into SAS, one of the fields has multiple entries, which the below codes scans and creates a new lookup table for all the different codes entered into a more manageable one to many table, the fields are separated by different characters including; space, comma, semi colon etc. The below code handles them fine, however I want to also scan by carraige return / new line. How do I add that to my scan?
Thanks.
data product_list;
set products(keep=id product_codes);
count=countw(product_codes);
do i = 1 to count;
product_code = scan(product_codes, i, ", .;");
output;
end;
drop count i product_codes;
run;
Guide Version: 5.1 (5.100.0.12019) (64-bit)
One way is to convert the line feeds using the translate function in a data step. Whether they will be '0D'x or '0A'x is dependent upon your computer's operating system, but you can include both to make sure. Nothing has to be changed to the code you posted. e.g.:
proc import datafile="c:\art\testfile.xlsx"
out=products replace dbms=xlsx;
getnames=yes;
sheet='Sheet1';
run;
data products;
set products;
product_codes=translate(product_codes,',','0A'x,'0D'x);
run;
data product_list;
set products(keep=id product_codes);
count=countw(product_codes);
do i = 1 to count;
product_code = scan(product_codes, i, ", .;");
output;
end;
drop count i product_codes;
run;
Art, CEO, AnalystFinder.com
One way is to convert the line feeds using the translate function in a data step. Whether they will be '0D'x or '0A'x is dependent upon your computer's operating system, but you can include both to make sure. Nothing has to be changed to the code you posted. e.g.:
proc import datafile="c:\art\testfile.xlsx"
out=products replace dbms=xlsx;
getnames=yes;
sheet='Sheet1';
run;
data products;
set products;
product_codes=translate(product_codes,',','0A'x,'0D'x);
run;
data product_list;
set products(keep=id product_codes);
count=countw(product_codes);
do i = 1 to count;
product_code = scan(product_codes, i, ", .;");
output;
end;
drop count i product_codes;
run;
Art, CEO, AnalystFinder.com
Awesome, nice thinking.
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.