data first(keep = major_ag ag_abbr first_year)
last(keep = major_ag ag_abbr last_year);
length major_ag $2;
set Data_Rep.c_agency;
major_ag = substr(ag_code,1,2);
select (major_ag);
when ('03') ag_abbr = 'HHS';
when ('06') ag_abbr = 'NSF';
when ('02') ag_abbr = 'DOD';
when ('04') ag_abbr = 'DOE';
when ('05') ag_abbr = 'NASA';
when ('01') ag_abbr = 'USDA';
when ('19') ag_abbr = 'ED';
when ('08') ag_abbr = 'DOC';
end;
output first;
output last;
run;
I am trying to also get the agencies that are not 03,06,02,04,05,01,08, and 19 in as Other agencies. I am not sure where to place that when statement in the same code.
I believe the statement you want is OTHERWISE. Like the below.
data first(keep = major_ag ag_abbr first_year)
last(keep = major_ag ag_abbr last_year);
length major_ag $2;
set Data_Rep.c_agency;
major_ag = substr(ag_code,1,2);
select (major_ag);
when ('03') ag_abbr = 'HHS';
when ('06') ag_abbr = 'NSF';
when ('02') ag_abbr = 'DOD';
when ('04') ag_abbr = 'DOE';
when ('05') ag_abbr = 'NASA';
when ('01') ag_abbr = 'USDA';
when ('19') ag_abbr = 'ED';
when ('08') ag_abbr = 'DOC';
otherwise ag_abbr = 'OTHER';
end;
output first;
output last;
run;
Jim
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.