BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
saza
Quartz | Level 8
  1. Create a format called YESNO where 1 = “Yes” and 2 = “No” and apply it to all variables in the dataset with that coding.
  2. Create formats for SEX and RACEETHN and apply them to the associated variables.
  3. Create an AGE variable that is patient age at hospitalization.
  4. Categorize the new AGE variable into a variable called AGEGROUP with the following categories:

1 = 0-4

2 = 5-17

3 = 18-49

4 = 50-64

5 = ≥65

  1. Create and apply a format for the new age category variable.
  2. Run a PROC FREQ to describe the number of hospital deaths by age group. Report which group experienced the most deaths over the period of observation.
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

In the article, 5 reasons to use PROC FORMAT to recode variables in SAS - The DO Loop, look for the PROC FORMAT step. That shows how to define a format. For example

 

proc format;
value YESNO
      0 = "Yes"
      1 = "No" 
      other = " ";
run;

proc freq data=covid1k;
format HospDeath IntenCare MechVent Asthma YESNO.;
tables HospDeath IntenCare MechVent Asthma;
run;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Show us what you have tried.

 

--
Paige Miller
saza
Quartz | Level 8
I tried to set 1 and 2 to yes or no In a new dates called "covid" but am getting errors.
data=covid;
set covidk.covid1k;
format 1 $YES;
format 2 $NO;
run;
PaigeMiller
Diamond | Level 26

So, there are plenty of examples out there in the world of correct use of formats. @Rick_SAS has pointed you to some. Here is another example, from the SAS documentation: http://documentation.sas.com/doc/en/pgmmvacdc/9.4/proc/n03qskwoints2an1ispy57plwrn9.htm

 

See if you can follow any of those examples.

--
Paige Miller
Rick_SAS
SAS Super FREQ

In the article, 5 reasons to use PROC FORMAT to recode variables in SAS - The DO Loop, look for the PROC FORMAT step. That shows how to define a format. For example

 

proc format;
value YESNO
      0 = "Yes"
      1 = "No" 
      other = " ";
run;

proc freq data=covid1k;
format HospDeath IntenCare MechVent Asthma YESNO.;
tables HospDeath IntenCare MechVent Asthma;
run;
saza
Quartz | Level 8
Thank you for your feedback! I believe I was able to crack the code using your resources:

libname covid1k '/home/u59291263/folder for sas lab';
run;

data=covid;
set covidk.covid1k;
format 1 $YES;
format 2 $NO;
run;

data covid;
set covid1k.covid1k;
format SEX 1= $YES
2= $NO;
run;
data covid;
set covid1k.covid1k;
format RACETHN 1= $YES
2= $NO;
run;

proc format AGE;
value AGEGROUP
1 = "0-4"
2 = "5-17"
3 = "18-49"
4 = "50-64"
5 = "≥65";
run;

proc freq data = covid;
table HospDeath;
format HospDeath AGE.;
run;
Rick_SAS
SAS Super FREQ

Here is a short introduction to using PROC FORMAT to define a format:

"Use PROC FORMAT to recode variables in SAS"

 

As shown in the article, you use the FORMAT statement to tell that SAS to display a variable's formatted values instead of its raw values. 

 

To "apply" a format to more than one variable, list all the variables after the word FORMAT and then put the name of the format at the end of the line. For example, to apply the YESNO format to four variables, you would use

format HospDeath IntenCare MechVent Asthma YESNO.;

 

Notice that the FORMAT statement needs to be INSIDE a DATA step or PROC/RUN boundary. It is not a global statement.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1136 views
  • 0 likes
  • 3 in conversation