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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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