BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kristiepauly
Obsidian | Level 7

Hi All, 

I'm trying to compare the prevalence of lung function between diabetics and non-diabetics. I have a data set that assigns a GOLD stage (-1 - 4) to each individual.  I separated the individuals into yes/no by diabetes status at baseline.  I need to write code that then lists the frequency of each stage for each diabetic yes/no (so both yes and no categories will have stages -1 -4). 

Here is the earlier code that I wrote to separate individuals by diabetes status yes/no: Works great

proc format; 
	value diabetes_baseline
	0 = 'No'
	1 = 'Yes'
	other = 'missing';
run;

data temp1;
	set temp;
	format diabetes_P1 diabetes_baseline.;
run;

Proc freq data = temp1;
	tables diabetes_P1;
	run;

I know this code is incorrect because I'm using the same stage numbers and giving them different names based on diabetes status.  I'm not even certain I should be using an if/then statement, but this is what I have....

proc format;
	value DMBaseline_Gold_Stage
	-1 = 'Gold Stage -1'
*insert others once this works; other = 'missing'; run; proc format; value Cntrl_Baseline_Gold_Stage -1 = 'Gold Stage -1' *insert others once this works; other = 'missing'; run; data temp1; set temp; where finalgold_P1; if finalgold_P1 = -1 and diabetes_baseline = 1 then DMBaseline_Gold_Stage = -1; else if finalgold_P1=-1 and diabetes_baseline = 0 then Cntrl_Baseline_Gold_Stage =-1; * fill in other stages here once code works; format DMBaseline_Gold_Stage DMBaseline_Gold_Stage.; format Cntrl_Baseline_Gold_Stage Cntrl_Baseline_Gold_Stage.; format diabetes_P1 diabetes_baseline.; run;

I don't need the new categories of DMBaseline_Gold_stage nor Cntrl_baseline_Gold_stage.  I simply want to list the frequency of each gold stage within the yes/no diabetes categories. 

Sorry this is so long. Any help is much appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you want to count values by more than 2 variables Proc Freq is still likely to be the tool but you need additional syntax.

 

I'm not sure what variable as you didn't describe your data very well but consider:

 

Proc freq data=temp;
  /* default table for two variables*/
   tables diabetes_P1 * Finalgold_p1;
  /* different layout table*/
   tables  diabetes_P1 * Finalgold_p1/ list;
  /* different layout but shows MISSING values in context*/
  tables diabetes_p1 *Finalgold_p1 / list missing;

/* you don't have to use a data step to assign a format you 
   do that in procedures that use the variable */
  format diabetes_p1 diabetes_baseline.;
run;

Strongly suggest that you provide actual example data and the appearance of the result you want. You should also tell us whether you want a data set (caution: some may not be possible or extremely hard to work with) or a report that people read. Also list by name variables that hold values. I have to guess that Finalgold_P1 is the variable that holds "each gold stage" because you did not mention the variable as holding those stages.

 

You can add options in proc freq to suppress percentages, column percentages, row percentages and cumulative totals if desired.

 

Proc Tabulate and Proc Report will also do counts as well as much more to make 'pretty' reports.

View solution in original post

2 REPLIES 2
ballardw
Super User

If you want to count values by more than 2 variables Proc Freq is still likely to be the tool but you need additional syntax.

 

I'm not sure what variable as you didn't describe your data very well but consider:

 

Proc freq data=temp;
  /* default table for two variables*/
   tables diabetes_P1 * Finalgold_p1;
  /* different layout table*/
   tables  diabetes_P1 * Finalgold_p1/ list;
  /* different layout but shows MISSING values in context*/
  tables diabetes_p1 *Finalgold_p1 / list missing;

/* you don't have to use a data step to assign a format you 
   do that in procedures that use the variable */
  format diabetes_p1 diabetes_baseline.;
run;

Strongly suggest that you provide actual example data and the appearance of the result you want. You should also tell us whether you want a data set (caution: some may not be possible or extremely hard to work with) or a report that people read. Also list by name variables that hold values. I have to guess that Finalgold_P1 is the variable that holds "each gold stage" because you did not mention the variable as holding those stages.

 

You can add options in proc freq to suppress percentages, column percentages, row percentages and cumulative totals if desired.

 

Proc Tabulate and Proc Report will also do counts as well as much more to make 'pretty' reports.

kristiepauly
Obsidian | Level 7

Thank you @ballardw. I apologize for the lack of information.  I thought I was including too much.  The "List" statement was exactly what I needed. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 341 views
  • 0 likes
  • 2 in conversation