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!
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').
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
Thank you for reply...My Value column also contain alphabets,alpha/numeric, so the below code truncated it.
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').
Thank you so much.. It worked.
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!
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.