BookmarkSubscribeRSS Feed
NDS
Calcite | Level 5 NDS
Calcite | Level 5

Hi,

I am using  PROC SUMMARY to add up some fields and check the number of fields that have been added as follows

PROC SUMMARY DATA = DQ_SET;

     BY deal_name asof_date;

     VAR field_val;

     OUTPUT OUT = DQ;

          SUM(field_val) = dq90p

          N(field_val) = check;

RUN;

As far as I understand this should create two new variables (dq90p and check) containing the summary statistics - however, in the DQ dataset (the outfile) - the summary stats have the name field_val.

Any idea what I have got wrong here?

Thanks

7 REPLIES 7
shivas
Pyrite | Level 9

Hi,

Try this..

PROC SUMMARY DATA = sashelp.class;

     class sex;

     VAR age;

     OUTPUT OUT = DQ

          SUM = dq90p

          N = check;

RUN;

Thanks,

Shiva

NDS
Calcite | Level 5 NDS
Calcite | Level 5

Hi Shivas,

Thanks for your response. I tried removing the field_val in the brackets, but it still gives me the same problem.

shivas
Pyrite | Level 9

Hi,

I tried with your code and it is working fine....just check the log if it giving any error or can you post some sample data.

data DQ_SET;

input deal_name $ asof_date :date9. field_val;

format asof_date date9.;

cards;

sss 20Mar2010 34

sss 21mar2010 44

rrr 21jun2010 55

rrr 22jun2010 66

sss 20Mar2010 34

sss 21mar2010 44

rrr 21jun2010 55

rrr 22jun2010 66

;

run;

proc sort data=dq_set;by deal_name asof_date;run;

PROC SUMMARY DATA = DQ_SET;

     BY deal_name asof_date;

     VAR field_val;

     OUTPUT OUT = DQ

          SUM(field_val) = dq90p

          N(field_val) = check;

RUN;

Thanks,

Shiva

NDS
Calcite | Level 5 NDS
Calcite | Level 5

Hi Shivas,

No error in the logs - I am running this inside a macro, could that make a difference? I am using MPRINT to look at the line by line execution of the macro and the PROC SUMMARY step runs fine.

Tom
Super User Tom
Super User

Are you sure you are not looking at the LABEL on the variable instead of its NAME?

Try this code with and without the label statement. And notice the difference in the label assigned to the new AGESUM variable.

proc summary data=sashelp.class;

  var age;

  label age='AGE';

  output out=want sum(age)=agesum;

run;

proc contents data=want; run;

Ksharp
Super User

There is a redundancy ';'  in the output statement.

OUTPUT OUT = DQ;

NDS
Calcite | Level 5 NDS
Calcite | Level 5

Sorry - the redundant ';' is a typo in the post. it is not in the actual code.


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 Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1695 views
  • 0 likes
  • 4 in conversation