Hi
I am trying to format Descriptive stats for age variable(numeric),
it giving me an error, any inputs will be appreciated.
Thanks kindly
Below is my desire output
| Descriptive Stat | All | Placebo | Cy 200 mg |
Age (years) |
|
|
|
|
| N | 227 | 115 | 112 |
| Mean (SD) | 27.53 ( 3.892 ) | 27.81 ( 3.586 ) | 27.25 ( 4.180 ) |
| Median | 28.00 | 28.00 | 27.00 |
| Q1 - Q3 | 25 - 30 | 25 - 30 | 25 - 30 |
| Min - Max | 19 - 41 | 19 - 41 | 19 - 41 |
11899
11900 /*Age: Descritive stats*/
11901
11902 %macro means (ds=,ds2=,var1=,var2=);
11903
11904 proc means data= &ds noprint;
11905 class &var1;
11906 var &var2;
11907 output out= &ds2 N=N Mean=Mean std=SD Median=Median Min=Min Max=Max Q1=Q1 Q3=Q3 ;
11908 run;
11909 %mend means;
11910
11911 %means (ds= sl_mh_2, ds2= age,var1= trta, var2= age);
NOTE: There were 378 observations read from the data set WORK.SL_MH_2.
NOTE: The data set WORK.AGE has 4 observations and 11 variables.
NOTE: Compressing data set WORK.AGE increased size by 100.00 percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE MEANS used (Total process time):
real time 1.22 seconds
cpu time 0.01 seconds
11912
11913
11914
11915 /*Format(Standardize) the Age descriptive stats for the table*/
11916
11917 %macro format (ds=, ds2=);
11918 data &ds2;
11919 set &ds;
11920 format N Mean SD Median Min Max Q1 Q3 ;
11921 drop _freq_ _type_;
11922
11923 N=put(N, 3.1);
11924 Mean=put(Mean,3.1);
11925 SD=put(SD, 2.1);
11926 Median=put(Median, 2.1);
11927 Min=put(Min, 2.1);
11928 Max=put(Max, 3.1);
11929 Q1=put(Q1, 2.1);
11930 Q3=put(Q3, 3.1);
11931 Mean(SD)=Mean||" "|| "("||SD||")";
11932 Min_Max=min||" "||"-"||" "||max;
11933 Q1_Q3 = p25||" "||"-"||" "||p75;
11934
11935 run;
11936 %mend format;
11937
11938 %format(ds= age, ds2= age_1);
ERROR: Undeclared array referenced: MEAN.
ERROR: Variable MEAN has not been declared as an array.
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
1:89 1:107 1:125 1:146 1:168 1:187 1:205 1:222
NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
1:245 2:7 2:24 2:44 2:57 2:77
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.AGE_1 may be incomplete. When this step was stopped there were 0
observations and 13 variables.
WARNING: Data set WORK.AGE_1 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
I will repeat it for a third and last time:
Mean(SD) is NOT a valid SAS name.
What should it represent?
The error is in line 11931. What did you want to do with this:
Mean(SD)=
?
i will be transposing the stats to get the desired below output
| Descriptive Stat | All | Placebo | Cy 200 mg |
Age (years) |
|
|
|
|
| N | 227 | 115 | 112 |
| Mean (SD) | 27.53 ( 3.892 ) | 27.81 ( 3.586 ) | 27.25 ( 4.180 ) |
| Median | 28.00 | 28.00 | 27.00 |
| Q1 - Q3 | 25 - 30 | 25 - 30 | 25 - 30 |
| Min - Max | 19 - 41 | 19 - 41 | 19 - 41 |
Thanks
Mean(SD) is not a valid SAS name, what should it do?
i am trying to concatenate like this
Mean(SD)=Mean||" "|| "("||SD||")";
so the out put after transpose should
| Descriptive Stat | All | Placebo | Cy 200 mg |
Age (years) |
|
|
|
|
| N | 227 | 115 | 112 |
| Mean (SD) | 27.53 ( 3.892 ) | 27.81 ( 3.586 ) | 27.25 ( 4.180 ) |
| Median | 28.00 | 28.00 | 27.00 |
| Q1 - Q3 | 25 - 30 | 25 - 30 | 25 - 30 |
| Min - Max | 19 - 41 | 19 - 41 | 19 - 41 |
I will repeat it for a third and last time:
Mean(SD) is NOT a valid SAS name.
What should it represent?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.