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

Hi, greetings, My SAS community! 

I have been helped so much by the Community. Even though I find no ways to directly return my thanks, I always cherish my thanks to you. 

 

I have a kind of annual firm financial data (panel) over 1999~2022.   

Based on this data set, I want to pick a random year between 1999 and 2022, fifty times. Each time, I want to further random-sample 500 obs. prior to 1 + the year randomly picked. Below are the SAS codes I created: 

%macro simul(rep=);
%do i=1 %to &rep;
DATA Compustat_6; SET Compustat_5; yr=rand('integer',1999,2022); run; 
DATA Survivors; SET Compustat_6; if fyear<yr+1; RUN; 
proc surveyselect data=Survivors method=srs rep=1 sampsize = 500 seed = 12345 out=Reg_surv; id _all_; run; 
proc reg data= Reg_surv outest=result_reg_surv noprint; 
model Tobinq = roa blev; run; 
proc append base= final_reg_surv data= result_reg_surv force;
%end;
%mend;
%simul(rep=50);

I have three questions about the results: 

(1) The dataset result_reg_surv  shows the intercept, coefficients of roa and blev. But I want to add standard error or t-values for the dependent variables, as well as their confidence intervals from each regression. What options should I enter where? 

(2) I want to append the simulated regression results onto the dataset final_reg_surv iteratively. But SAS reports an error message that the variables Intercept, roa, and blev are not found in final_reg_surv . What's wrong with my coding? 

(3) After I executed the codes, I opened the dataset Reg_surv to check the data on which the 50th regression was made. As I checked the variable yr, yr comprises various years. What I expected was that yr should be a single year value from the last 50th yr=rand('integer',1999,2022) random pick-up. 

 

How should I fix these problems based on the codes I created? 

 

Thanks in advance, happy X-mas! 

 

Sincerely, 

KS -                       

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

For your first question :

 

ods select none;
proc reg data=sashelp.class ;
model weight=age height/clb;
ods output  ParameterEstimates= result_reg_surv ;
quit;
ods select all;

 

 

For your second question:

1)It looks like there are some dataset you can not fit a model,

  Is there any ERROR or WARNING information in LOG ?

 

2)I am not sure .But you need delete dataset "final_reg_surv " before invoking macro "%simul(rep=50);" .  Like:

.............
options nodsnferr;
proc delete data=final_reg_surv  ; run;
%simul(rep=50);

 

 

 

For your third question:

You could add an ID variable to mark the id number of iterative.

 

%macro simul(rep=);
%do i=1 %to &rep;
DATA Compustat_6; SET Compustat_5; yr=rand('integer',1999,2022); run; 
DATA Survivors; SET Compustat_6; if fyear<yr+1; RUN; 
proc surveyselect data=Survivors method=srs rep=1 sampsize = 500 seed = 12345 out=Reg_surv; id _all_; run; 
proc reg data= Reg_surv outest=result_reg_surv noprint; 
model Tobinq = roa blev; run; 

data result_reg_surv ;
 set result_reg_surv ;
 _id_=&i. ;
run;

proc append base= final_reg_surv data= result_reg_surv force;
%end;
%mend;
%simul(rep=50);

 

 

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

For your first question :

 

ods select none;
proc reg data=sashelp.class ;
model weight=age height/clb;
ods output  ParameterEstimates= result_reg_surv ;
quit;
ods select all;

 

 

For your second question:

1)It looks like there are some dataset you can not fit a model,

  Is there any ERROR or WARNING information in LOG ?

 

2)I am not sure .But you need delete dataset "final_reg_surv " before invoking macro "%simul(rep=50);" .  Like:

.............
options nodsnferr;
proc delete data=final_reg_surv  ; run;
%simul(rep=50);

 

 

 

For your third question:

You could add an ID variable to mark the id number of iterative.

 

%macro simul(rep=);
%do i=1 %to &rep;
DATA Compustat_6; SET Compustat_5; yr=rand('integer',1999,2022); run; 
DATA Survivors; SET Compustat_6; if fyear<yr+1; RUN; 
proc surveyselect data=Survivors method=srs rep=1 sampsize = 500 seed = 12345 out=Reg_surv; id _all_; run; 
proc reg data= Reg_surv outest=result_reg_surv noprint; 
model Tobinq = roa blev; run; 

data result_reg_surv ;
 set result_reg_surv ;
 _id_=&i. ;
run;

proc append base= final_reg_surv data= result_reg_surv force;
%end;
%mend;
%simul(rep=50);

 

 

 

KS99
Obsidian | Level 7

Hi, nice to see you again, K-Sharp!! 

I opened your message and got your codes. 

I inserted them into my old codes after modifying them a little bit, and they work perfectly as I wanted them! 

Thank you, K-Sharp, 

Wish you great holidays! 

 

KS - 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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