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

how many people are considered to have a valid depression score assuming a valid depression score is a 9 or higher and how do i code for this ?

Item MTH22: PHQ score

                                                               _____________________________ _____________

  Categories                                                        Frequency        CumFreq      %  Cum %

______________________________________________________________ _____________________________ _____________

   0                                                                     2749           2749   37.1   37.1

   1                                                                     1155           3904   15.6   52.7

   2                                                                      821           4725   11.1   63.8

   3                                                                      646           5370    8.7   72.5

   4                                                                      476           5847    6.4   78.9

   5                                                                      343           6190    4.6   83.5

   6                                                                      302           6491    4.1   87.6

   7                                                                      217           6709    2.9   90.5

   8                                                                      175           6884    2.4   92.9

   9                                                                      124           7008    1.7   94.6

  10                                                                       69           7077    0.9   95.5

  11                                                                       72           7149    1.0   96.5

  12                                                                       52           7201    0.7   97.2

  13                                                                       37           7237    0.5   97.7

  14                                                                       47           7284    0.6   98.3

  15                                                                       32           7316    0.4   98.7

  16                                                                       27           7342    0.4   99.1

  17                                                                       16           7358    0.2   99.3

  18                                                                       15           7373    0.2   99.5

  19                                                                        6           7380    0.1   99.6

  20                                                                       12           7391    0.2   99.7

  21                                                                        3           7394    0.0   99.8

  22                                                                        6           7400    0.1   99.9

  23                                                                        7           7407    0.1  100.0

24                                                                        2           7409    0.0  100.0

  25                                                                        1           7410    0.0  100.0

  27                                                                        1           7410    0.0  100.0

______________________________________________________________ _____________________________ _____________

  Total                                                                  7410           7410  100.0  100.0

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You don't say what to do about the other scores.

If the question is treating a list or range of values as a group then one of the slickest features in SAS comes into play: custom formats.

You didn't mention the name of your data set or even the variable name, so I am guessing the MTH22 is the variable that you ran proc freq with.

So try:

Proc format;
value depressionscore
9-high ='Valid depression Score'
;

proc freq data=yourdataset;
   tables mth22;
   format mth22 depressionscore.;
run;

The format will assign all values of 9 or more with the text, may be to long, of "Valid Depression Score" and will be displayed in proc freq as one line with the total count and appropriate percentages.

Formats will create groups for analysis, such as Proc Freq or in other procs, reporting or for graphing (though some limits with custom date/time/datetime formats).

 

One of the strengths of a format is that you can have multiple formats related to a topic and just change the format for an analysis. You could for example have some range of scores mean "mild" "moderate" or "severe", or another that just indicates over/under some specific value of interest.

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

@ChanelB wrote:

how many people are considered to have a valid depression score assuming a valid depression score is a 9 or higher and how do i code for this ?

 


Not sure programming is needed here: 9 or higher would be the total number of people, 7410 minus the number of people with 8 or lower scores 6884.

 

but if you really must do the programming

 

proc format;
    value gt9 low-8='<9' 9-high='>=9';
run;

proc freq data=have;
    tables mth22/noprint out=count;
    format mth22 gt9.;
run;

 

 

@ChanelB please go back to your original post and change the subject to briefly describe the problem you are having. "Mental" means nothing to anyone and should be changed so that it briefly describes the problem.

--
Paige Miller
ChanelB
Calcite | Level 5

This is how it looks like as of now 

Libname Chanel 'C:\Users\chane\Desktop\Mental Health\NPIR82SD';
proc format;

Proc format;
Value depressionscore
9-high='valid depression score';
run;

Proc freq data=NPIR82SD;
tables MTH22;
Format MTH22 depressionscore;
run;


value F00001_
1 = "Baisakh"
2 = "Jestha"
3 = "Asadh"
4 = "Shrawan"
5 = "Bhadra"
6 = "Ashwin"
7 = "Kartik"
8 = "Mangsir"
9 = "Poush"
10 = "Magh"
11 = "Falgun"
12 = "Chaitra"
;
value F00002_
9998 = "Don't know year"
9997 = "Not applicable/inconsistent"
;
value F00003_
1 = "15-19"
2 = "20-24"
3 = "25-29"
4 = "30-34"
5 = "35-39"
6 = "40-44"
7 = "45-49"
;
value F00004_
1 = "Month and year - information complete"
2 = "Month and age - year imputed"
3 = "Year and age - month imputed"
4 = "Year and age - year ignored"
5 = "Year - age/month imputed"
6 = "Age - year/month imputed"
7 = "Month - age/year imputed"
8 = "None - all imputed"
;
value F00005_
1 = "Completed"
2 = "Not at home"
3 = "Postponed"
4 = "Refused"
5 = "Partially completed"
6 = "Respondent incapacitated"
7 = "Other"
;
value F00006_
0 = "No calendar"
;
value F00007_
0 = "No calendar"
;
value F00008_
0 = "No calendar"
;
value F00009_
0 = "All woman sample"
1 = "Ever married sample"
;

PaigeMiller
Diamond | Level 26

What are you trying to say? Just showing us a bunch of code without telling us what is wrong or what is right doesn't seem to help.

 

Repeating my earlier comment: @ChanelB please go back to your original post and change the subject to briefly describe the problem you are having. "Mental" means nothing to anyone and should be changed so that it briefly describes the problem.

--
Paige Miller
ballardw
Super User

@ChanelB wrote:

This is how it looks like as of now 

Libname Chanel 'C:\Users\chane\Desktop\Mental Health\NPIR82SD';
proc format;

Proc format;
Value depressionscore
9-high='valid depression score';
run;

Proc freq data=NPIR82SD;
tables MTH22;
Format MTH22 depressionscore;
run;

 


To use a format the name of the format ends in a period.

That should read:

Format MTH22 depressionscore. ;

 

Since you placed PROC FREQ in the middle of the Proc format the code after proc freq should throw a bunch errors about code errors.

 

SAS when it sees some sorts of statements, such as Proc or Data statement, assumes that the previous proc or data step is complete and will attempt to execute the code. However,  the Value statements, which belong to Proc Format, do not have a Proc Format statement preceding them any more so are errors.

ballardw
Super User

You don't say what to do about the other scores.

If the question is treating a list or range of values as a group then one of the slickest features in SAS comes into play: custom formats.

You didn't mention the name of your data set or even the variable name, so I am guessing the MTH22 is the variable that you ran proc freq with.

So try:

Proc format;
value depressionscore
9-high ='Valid depression Score'
;

proc freq data=yourdataset;
   tables mth22;
   format mth22 depressionscore.;
run;

The format will assign all values of 9 or more with the text, may be to long, of "Valid Depression Score" and will be displayed in proc freq as one line with the total count and appropriate percentages.

Formats will create groups for analysis, such as Proc Freq or in other procs, reporting or for graphing (though some limits with custom date/time/datetime formats).

 

One of the strengths of a format is that you can have multiple formats related to a topic and just change the format for an analysis. You could for example have some range of scores mean "mild" "moderate" or "severe", or another that just indicates over/under some specific value of interest.

ChanelB
Calcite | Level 5

 I did that and it said that, it said no data set open to look up files. So i am confused

ChanelB
Calcite | Level 5

Also, how are the scores distributed among the women.

Which variable represents depression?

Is it continuous, binary, or categorical?

The distribution of women whose data are considered have valid information that are categorized as depressed vs not depressed.

I mentioned before that i know a little sas but i am not an expect and i need a little guide to do this 

ballardw
Super User

@ChanelB wrote:

 

Which variable represents depression?  

How would we know? We don't have your data.

Perhaps if your run

PROC CONTENTS data=put_the_name_of_your_dataset_here;

run;

 

and share the results it may provide us enough information.

 

To get analysis of a subset of data depends on your data. Some variable would have to indicate if the record is from a woman or not. That  variable would have some value.

Choices would be to

1) subset the data using something like

Proc freq data=again_put_your_data_set_name_here;
    where  thenameofthevariablethatindicatessex ='the actual value that indicates women';
   tables ....
   ;
run;

Or use the variable in a tables statement

Proc freq data= ... ;
   tables gendervarname * depressionvarname;
run;
ballardw
Super User

@ChanelB wrote:

 I did that and it said that, it said no data set open to look up files. So i am confused


What is the NAME of YOUR data set?

I said that you had not provided one. Replace the text "yourdataset" with the actual name of the data set you have.

And the actual name of your variable if it is different.

 

Details matter. If you do not share them we have no way to know what you actually need.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 9 replies
  • 12294 views
  • 0 likes
  • 3 in conversation