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

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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

hi @mauri0623 

Just add 

otherwise ag_abbr = 'Other Agencies'

after the last when

View solution in original post

2 REPLIES 2
ErikLund_Jensen
Rhodochrosite | Level 12

hi @mauri0623 

Just add 

otherwise ag_abbr = 'Other Agencies'

after the last when

jimbarbour
Meteorite | Level 14

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 904 views
  • 1 like
  • 3 in conversation