Hi,
I can't figure out why this code is not working. I am trying to insert dummy rows into this data set when there are no observations found on it. If I run the proc sql alone, it will insert the rows. However, when I use the call execute if noobs=0, no observations are inserted.
data _null_;
set msrflow.msrflow_loansfunded_10YR_append;
if nobs=0 then do;
call execute(
'proc sql;
insert into msrflow.msrflow_loansfunded_10YR_append
(
PRIMARY_LOAN_KEY
,INVESTOR_LOAN_ID
,SELLER_LOAN_NUMBER
,PNC_LOAN_NUMBER
,STATUS
,INVESTOR
,FUNDING_DATE
,NOTE_BALANCE
,NOTE_RATE
,SERVICE_FEE
,LTV
,FICO
,SRP_RATE
,SRP_AMOUNT
,PRODUCT
,ESCROW_FLAG
,PURPOSE
,TIMEFRAME
,PCT_TOTAL_UPB_PURCHASE
,PCT_TOTAL_UPB_REFI
,PCT_TOTAL_CNT_ESCROW
,PCT_TOTAL_CNT_NONESCROW
,WGT_AVG_10YR
)
values (0,"","","","","",.,0,0,0,0,0,0,0,"","","","MTD",0,0,0,0,0)
values (0,"","","","","",.,0,0,0,0,0,0,0,"","","","YTD",0,0,0,0,0)
values (0,"","","","","",.,0,0,0,0,0,0,0,"","","","LTD",0,0,0,0,0)
;
quit;'
);
end;
run;
When a set statement attempts to read beyond the end of a data set, the data step immediately stops. With zero obs, the first SET provokes that response. There is a way, however, to get the proper nobs:
data _null_;
if 0 then set msrflow.msrflow_loansfunded_10YR_append nobs=nrecs;
put nrecs=;
if nrecs=0 then call execute ('....');
stop;
run;
This works because:
Maxim 2: read the log. You'll find a NOTE that nobs is uninitialized. You forgot the nobs= option in the set statement, and you need to move the set statement after the end and before the run.
When a set statement attempts to read beyond the end of a data set, the data step immediately stops. With zero obs, the first SET provokes that response. There is a way, however, to get the proper nobs:
data _null_;
if 0 then set msrflow.msrflow_loansfunded_10YR_append nobs=nrecs;
put nrecs=;
if nrecs=0 then call execute ('....');
stop;
run;
This works because:
Thank you both for the help. Both solutions worked for me and were very helpful.
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!
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.