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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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