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

I am trying to import excel file to SAS using Proc Import.

There are 3 columns in Excel file.One of the column have different values separated by random delimiters like comma or space or 'and' or double space..seems very random.

 

Given Excel file data

 

ID            Values                                   Date

1             2017138                          2/16/2018

2             2017456 2017778           2/16/2018

3             2017458 and 309878      2/16/2018

4             20178  2078654              2/15/2018

 

 

Output needed:

 

ID             Values                         Date

1              2017138                    2/16/2018

2              2017456                    2/16/2018

2              2017778                    2/16/2018

3               2017458                    2/16/2018

3              309878                      2/16/2018

 

I want like above output,treat the values for ID 2 into two separate observations, Is it possible to create output (multiple observation) like this from a single record during proc import or in Data step/Data step after importing?

 

Thanks for checking!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Then you need to know the complete list of values to ignore.  For example:

 

data want;

set imported_data;

newvar = values;

if values=' ' then output;

else do _n_=1 to countw(newvar);

   values = scan(newvar, _n_);

   if values not in ('and') then output;

end;

drop newvar;

run;

 

You can add to the list of values in parentheses (which right now contain just the one item 'and').

View solution in original post

4 REPLIES 4
Astounding
PROC Star

While you can't do this during the import, a DATA step can handle this pretty well.

 

data want;

set imported_data;

newvar = compress(values, , 'kds');

do _n_=1 to countw(newvar);

   values = scan(newvar, _n_);

   output;

end;

drop newvar;

run;

 

"kds" = keep digits and spaces

Kalai2008
Pyrite | Level 9

Thank you for reply...My Value column also contain alphabets,alpha/numeric, so the below code truncated it.

Astounding
PROC Star

Then you need to know the complete list of values to ignore.  For example:

 

data want;

set imported_data;

newvar = values;

if values=' ' then output;

else do _n_=1 to countw(newvar);

   values = scan(newvar, _n_);

   if values not in ('and') then output;

end;

drop newvar;

run;

 

You can add to the list of values in parentheses (which right now contain just the one item 'and').

Kalai2008
Pyrite | Level 9

Thank you so much.. It worked. 

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
  • 4 replies
  • 814 views
  • 0 likes
  • 2 in conversation