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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.