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."
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'.
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?
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);
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.