Hi,
I have a field that contains (ideally) a single three-number code, e.g., 123. Variations on this ideal case include:
I think that's about it. Each row (observation) contains other fields. When my code field is empty, I'd like to just ignore that observation. If there's only one code, I'll save (output) the observatoin. If there's two unique codes, I'd like to output the observation twice, once for each code. If the code is a lot trickier for the 123; 123 case, I can live with a duplicate. I was thinking of using some of the prx functions. Any suggestions?
Thanks! Bruce
Is this a text file you are reading or is this "field" already a SAS variable?
By "ignore" do you mean remove from the data set?
Scan should work just fine if this is already a SAS varaible.
data have;
infile datalines truncover;
input code $ 1-15 ;
datalines4;
;
123;
123; 123
123 456
123; 456
123; 456;
123; 456;
;;;;
run;
data want;
set have;
if countw(code,' ;,')>0 then do i=1 to (countw(code,' ;,'));
NewCode=scan(code,i,' ;,');
output;
end;
drop i;
run;
Is this a text file you are reading or is this "field" already a SAS variable?
By "ignore" do you mean remove from the data set?
Scan should work just fine if this is already a SAS varaible.
data have;
infile datalines truncover;
input code $ 1-15 ;
datalines4;
;
123;
123; 123
123 456
123; 456
123; 456;
123; 456;
;;;;
run;
data want;
set have;
if countw(code,' ;,')>0 then do i=1 to (countw(code,' ;,'));
NewCode=scan(code,i,' ;,');
output;
end;
drop i;
run;
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.