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

hello 

i need to make sure about kind of code whether it is correct or not

first i usually use creating a variable (var_lag) to calculate the delta of that var for instance total assets( TA_lag) or inventory 

then i used the statement as follows 

 data real_em;
 set erm_var;
 CFLO_real= (CSFO/TA_lag);
TA1=(1/TA_lag);
S1= (sales/TA_lag);
S2= (delta_sales/TA_lag);
S3= (delta_sales_lag/TA_lag);
S4= (sales_lag/TA_lag);
PRODa= (PROD/TA_lag);
EXPENa= (EXPEN/TA_lag);
run; 

 then i tried to change my way by using this statement directly without creating var_lag

as follows

 data attempt; set erm_var;
 cshflo=csfo/lag(Total_assets);
 TA1=(1/lag(Total_assets));
S1= (sales/lag(Total_assets));
S2= (delta_sales/lag(Total_assets));
S3= (delta_sales_lag/lag(Total_assets));
S4= (sales_lag/lag(Total_assets));
PRODa= (PROD/lag(Total_assets));
EXPENa= (EXPEN/lag(Total_assets));
 run;

of course by first way there were a lot of missing value while in the second way less than, so please which way is correct 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Using one variable instead of multiple lag() calls renders the same result:

data test1;
set sashelp.class;
s1 = lag(age);
s2 = 1/lag(age);
s3 = weight/lag(age);
run;

data test2;
set sashelp.class;
agelag = lag(age);
s1 = agelag;
s2 = 1/agelag;
s3 = weight/agelag;
drop agelag;
run;

proc compare
  base=test1 
  compare=test2
  criterion=0.00001
  method=RELATIVE
  out=comp(label="Compare Data for TEST1 and TEST2")
  outstats=stat(label="Compare Data Summary Statistics for TEST1 and TEST2")
  outnoequal
  maxprint=50
;
var Name Sex Age Height Weight s1 s2 s3;
with Name Sex Age Height Weight s1 s2 s3;
run;

Dataset comp will be empty, meaning both datasets are identical.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Using one variable instead of multiple lag() calls renders the same result:

data test1;
set sashelp.class;
s1 = lag(age);
s2 = 1/lag(age);
s3 = weight/lag(age);
run;

data test2;
set sashelp.class;
agelag = lag(age);
s1 = agelag;
s2 = 1/agelag;
s3 = weight/agelag;
drop agelag;
run;

proc compare
  base=test1 
  compare=test2
  criterion=0.00001
  method=RELATIVE
  out=comp(label="Compare Data for TEST1 and TEST2")
  outstats=stat(label="Compare Data Summary Statistics for TEST1 and TEST2")
  outnoequal
  maxprint=50
;
var Name Sex Age Height Weight s1 s2 s3;
with Name Sex Age Height Weight s1 s2 s3;
run;

Dataset comp will be empty, meaning both datasets are identical.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 559 views
  • 1 like
  • 2 in conversation