BookmarkSubscribeRSS Feed
oraha
Calcite | Level 5

 

 

This is my code. I am unable to calculate today and days. It's not printing anything. What format do i need to use ?
proc report data=profile (where=(state in('NY' , 'CA')));
column Acct_ID Name today days Birthday Age Sex State Cust_Type Product Balance Last_Tran_Date;
define state / order;
define Acct_ID / order width=6;
define Name / order "Name" width=5;
define today /computed format= date9. ;
define days / computed format=mmddyy10. ;
define Birthday / order format=mmddyy10. ;
define Sex / order noprint;
define Cust_Type / order noprint;
define Product / order noprint;
define Age / computed format= mmddyy10.;
Define Balance / order width=5;
define Last_Tran_Date / order format=mmddyy10.;
compute after today;
today = date(),anydtdte.;
endcomp;
compute before days;
days = today - Birthday;
endcomp;
compute before Age;
Age = floor(days / 365);
endcomp;
/*BREAK AFTER Balance / SUMMARIZE;*/
run;
quit;

 

5 REPLIES 5
SASKiwi
PROC Star

You would be better off calculating age and adding as a column to your data before using PROC REPORT. There are many posts on this topic in the SAS Community. Try searching for them. This is one example:

https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434973#M107998

Reeza
Super User

This is my code. I am unable to calculate today and days. It's not printing anything

Does your log have errors? Is it calculating anything? Can you provide sample data? 

 

Here are instructions on how to provide sample data

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 


@oraha wrote:

 

 

This is my code. I am unable to calculate today and days. It's not printing anything. What format do i need to use ?
proc report data=profile (where=(state in('NY' , 'CA')));
column Acct_ID Name today days Birthday Age Sex State Cust_Type Product Balance Last_Tran_Date;
define state / order;
define Acct_ID / order width=6;
define Name / order "Name" width=5;
define today /computed format= date9. ;
define days / computed format=mmddyy10. ;
define Birthday / order format=mmddyy10. ;
define Sex / order noprint;
define Cust_Type / order noprint;
define Product / order noprint;
define Age / computed format= mmddyy10.;
Define Balance / order width=5;
define Last_Tran_Date / order format=mmddyy10.;
compute after today;
today = date(),anydtdte.;
endcomp;
compute before days;
days = today - Birthday;
endcomp;
compute before Age;
Age = floor(days / 365);
endcomp;
/*BREAK AFTER Balance / SUMMARIZE;*/
run;
quit;

 


 

oraha
Calcite | Level 5

Its's not calculating anything, just empty columns for today and days. It's not giving error.

Sample data:

Acct_ID

Name

Birthday

Sex

State

Cust_Type

Product

Balance

Last_Tran_Date

1001

John

1/1/1962

M

CA

Gold

Checking

1000

9/1/2015

1002

Mary

2/1/1972

F

CA

Silver

Saving

2000

10/1/2015

1003

Peter

3/1/1982

M

NY

Gold

Loan

3000

10/3/2016

1004

Mary

4/1/1992

F

NY

Silver

Checking

4000

9/17/2016

1005

Linda

5/1/1994

F

WA

Gold

Saving

5000

 

1006

Susan

6/1/1997

F

WA

Gold

Loan

1000

9/15/2016

Cynthia_sas
SAS Super FREQ

Hi:
I'm not in a position to run any code now, but you should search the Forums for previous tracks about the PROC REPORT "left-to-right" rule.

But first, you have some basic PROC REPORT errors. I would imagine that you are getting errors in the log for your COMPUTE AFTER TODAY or COMPUTE BEFORE DAYS that you can only do break processing on GROUP or ORDER items. But TODAY, AGE and DAYS are all COMPUTED, so BREAK processing such as COMPUTE BEFORE/AFTER will NOT work.

Next, your code is violating the "left-to-right" rule which is that if I have a COLUMN statement like this:
COLUMN var1 var2 var3 var3 var5;

Then when PROC REPORT is putting VAR1 on the report row, it has no visibility of the values for VAR2, VAR3, VAR4 or VAR5.

When VAR1 and VAR2 have been placed on the report row, there is still no visibility of VAR3, VAR4 or VAR5. At this point in timing, a COMPUTE block for VAR2 can refer to VAR1; however, a COMPUTE block for VAR1 CANNOT refer to VAR2.

Processing continues the same way. At the point in time when VAR4 is placed on the report row, a COMPUTE block for VAR4 could reference VAR1, VAR2 and VAR3, but could NOT reference VAR5.

There have been many different forum postings about the left-to-right rule. But even so, you've got to fix your other problems first.

Cynthia

singhsahab
Lapis Lazuli | Level 10

Hello,

 

You have to follow left to right rule of proc report before computing any new variable. Here is an example as per your data.. 

Hope this will help to resolve your problem..

 

proc report data=profil;
column Acct_ID Name  Birthday today days age;
define acct_id/order;
define name /display;
define birthday/display;
define today/computed format=date9.;
compute today;
 today=today();
endcomp;
compute days;
days= _c4_ - _c3_;
endcomp;
compute age;
age=floor(_c5_/365);
endcomp;
run;

 

Thanks :

🙂 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 685 views
  • 0 likes
  • 5 in conversation