Help using Base SAS procedures

PROC SUMMARY not creating new variable names in OUTPUT statement

Reply
Occasional Contributor NDS
Occasional Contributor
Posts: 10

PROC SUMMARY not creating new variable names in OUTPUT statement

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

Super Contributor
Posts: 349

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

Hi,

Try this..

PROC SUMMARY DATA = sashelp.class;

     class sex;

     VAR age;

     OUTPUT OUT = DQ

          SUM = dq90p

          N = check;

RUN;

Thanks,

Shiva

Occasional Contributor NDS
Occasional Contributor
Posts: 10

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

Hi Shivas,

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

Super Contributor
Posts: 349

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

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

Occasional Contributor NDS
Occasional Contributor
Posts: 10

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

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.

Super User
Super User
Posts: 6,502

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

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;

Super User
Posts: 9,687

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

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

OUTPUT OUT = DQ;

Occasional Contributor NDS
Occasional Contributor
Posts: 10

Re: PROC SUMMARY not creating new variable names in OUTPUT statement

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


Ask a Question
Discussion stats
  • 7 replies
  • 234 views
  • 0 likes
  • 4 in conversation