BookmarkSubscribeRSS Feed
michelle05
Fluorite | Level 6

The question reads as follow.  I keep getting an error from the ID.

You have raw data consisting of ID (character), GENDER (numeric 1 = Male, 2 = Female), SES (character: L= Low, M= Medium, H=High), DRUG (character: A-H), and AGE (numeric). First create three formats. One for GENDER, one for SES, and one to group ages into three groups: <20, 21-40, and 41 and older. Write a DATA step to read the following space delimited data and create a data set called QUES2. Format only SES and GENDER here. Also, add labels for SES (Socioeconomic Status), DRUG (Drug Group), and AGE (Age of Subject). Also in the DATA step, create a new variable, COST, with a value of LOW when the value of DRUG is A,C,F, or B and a value of HIGH otherwise. Assume there may be missing values for DRUG. Use PROC PRINT to obtain a listing of the data set. Next, compute frequencies for SES, COST, and AGE, where AGE is formatted into the three age groups mentioned.

Here are some sample data lines to work with:

001 1 L B 15

002 2 M Z 35

003 2 H F 76

004 1 L C 21

005 2 H . 58

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try the below code

proc format;
value gen
1='Male'
2='Female';

value $ses
'L'='Low'
'M'='Medium'
'H'='High';

value age
low-20='<=20'
21-40='21-40'
41-high='41 and older';
run;

data ques2;
input id$ gender ses$ drug$ age;
format gender gen. ses $ses.;
if drug in ('A' 'B' 'C' 'F' ) then COST='LOW ';
else COST='HIGH';
label ses='Socioeconomic Status'
drug='Drug Group'
age='Age of Subject';
cards;
001 1 L B 15
002 2 M Z 35
003 2 H F 76
004 1 L C 21
005 2 H . 58
;


proc print data=ques2;
run;

proc freq data=ques2;
table ses;
run;

proc freq data=ques2;
table cost;
run;

proc freq data=ques2;
table age;
format age age.;
run;

Thanks,
Jag
michelle05
Fluorite | Level 6

Thank you so much!  I worked it out a little different but still got the same results.  Thank you again!

Kurt_Bremser
Super User

So what have you done already, and where did it not meet your expectations? Please post your code and log.

Use the "little running man" button for code, and the {i} button for logs and textual input data.

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!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1100 views
  • 1 like
  • 3 in conversation