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

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
(N=227)

Placebo
n=115)

Cy 200 mg
(n=112)

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



1 ACCEPTED SOLUTION
5 REPLIES 5
azhar7860
Obsidian | Level 7

i will be transposing the stats to get the desired below output

 

 

 

 

Descriptive Stat

All
(N=227)

Placebo
n=115)

Cy 200 mg
(n=112)

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

azhar7860
Obsidian | Level 7

i am trying to concatenate like this
Mean(SD)=Mean||" "|| "("||SD||")";

so the out put after transpose should

 

 

 

Descriptive Stat

All
(N=227)

Placebo
n=115)

Cy 200 mg
(n=112)

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1002 views
  • 0 likes
  • 2 in conversation