BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rhys
Obsidian | Level 7

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)

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

 

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

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

 

Rhys
Obsidian | Level 7

Awesome, nice thinking. 

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3086 views
  • 1 like
  • 2 in conversation