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 2025: Call for Content

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!

Submit your idea!

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
  • 3477 views
  • 1 like
  • 2 in conversation