BookmarkSubscribeRSS Feed
andrewfau
Fluorite | Level 6

 

data employees;
infile 'c:\users\************\*******\employees.dat';
input ssn :$1-11 name & $12-28 dob :date10. paygrade $ monsal :comma6.2 job & :$71-100;
if paygrade = 'gr20' then do;
minimum = 50000.00;
maximum = 70000.00;
end;

age = int(yrdif(dob, today (), 'age'));
put monsal dollar7.2;

run;

I am trying to create min and max variables based on the paygrade codes. This is an exercise that comes out of the "The Little SAS Book." When I run this program I get two new variables for minimum and maximum but there are just periods in the columns. I tried using 50000 instead of 50000.00 and that didn't work either. Do I have a formatting problem with the numeric data or is my program not written correctly.

 

This is exercise 31d from Chapter 3 in "Exercises and Projects for The Little SAS Book."

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You get the periods because at no time in your data do you have paygrade='gr20'. I don't know if this is just a capitalization mismatch, or that 'gr20' never appears in your data. You need to write code to tell SAS what it should do if it finds paygrade is not equal to 'gr20'.

--
Paige Miller
andrewfau
Fluorite | Level 6
data employees;

input ssn :$1-11 name & $12-28 dob :date10. paygrade $ monsal :comma6.2 job & :$71-100;
if paygrade = 'GR20' then do;
minimum = 50000;
maximum = 70000;
end;
if paygrade = 'GR21' then do;
minimum = 55000;
maximum = 75000;
end;
if paygrade = 'GR22' then do;
minimum = 60000;
maximum = 85000;
end;
if paygrade = 'GR23' then do;
minimum = 70000;
maximum = 100000;
end;
if paygrade = 'GR24' then do;
minimum = 80000;
maximum = 120000;
end;
if paygrade = 'GR25' then do;
minimum = 100000;
maximum = 150000;
end;
if paygrade = 'GR26' then do;
minimum = 120000;
maximum = 200000;
end;
age = int(yrdif(dob, today (), 'age'));
put monsal dollar7.2;

run;

Is there a way i can condense those if then statements or do I need to write them all individually for a problem like this?

Reeza
Super User

You could probably do an array. Not sure it's less code in the end, but easier to manage perhaps?

 

array min_pay(20:26) (50000 55000 60000 70000 ... 120000);
array max_pay(20:26) (70000 75000 .. 200000);

grade = input(compress(paygrade, ,'kd'), 8.);
minimum = min_pay(grade);
maximum = max_pay(grade);
error_prone
Barite | Level 11
Things total check in the data-file: is there any obs having paygrade "gr20"? Both letters have time be in low case.
Maximum and minimum are only set of paygrade is gr20, any obs having another value will show missing value fit both vars.
andrewfau
Fluorite | Level 6
Gotcha. It was the lowercase that was the problem. Thanks!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 6 replies
  • 3111 views
  • 0 likes
  • 4 in conversation