08-11-2017 12:25 PM
I am trying to compute the same variables across an library of datasets. The problem is, the month and year vars are not included in the files. The code below interpreds year and month from the file name and is supposed to insert yy for year, and mm for month into the file as new variables. However, the code listed below is inserting year and month as the year and month of the most recent file read on the last dataset. Any suggestions?
libname rtot 'H:/...../.../RTOT';
libname test 'H:/...../.../Test';
proc contents data=rtot._all_ memtype=data out=out noprint;
proc sort data=out;
by memname name; run;
by memname name;
set a end=last;
by memname name;
call symput('DS'|| left(_n_),trim(memname));
call symput('yy',substr(memname,10,2)); /*Var Year is not found in summary data*/
call symput('mm',substr(memname,12,2)); /*Month is not found in summary data*/
if last then call symput('TOTAL',left(_n_));
%do i=1 %to &total;
if count gt 0 then resp_rate=round(usable/count*100,1);
MON="&mm"; /*insert month into file*/
Yr="&yy"; /*insert year into file*/
Credits to: *http://www2.sas.com/proceedings/sugi27/p084-27.pdf;
08-11-2017 12:29 PM
08-11-2017 12:50 PM - edited 08-11-2017 12:51 PM
data _null_; set a end=last; by memname name; call symput('DS'|| left(_n_),trim(memname)); call symput('yy',substr(memname,10,2)); /*Var Year is not found in summary data*/ call symput('mm',substr(memname,12,2)); /*Month is not found in summary data*/ if last then call symput('TOTAL',left(_n_)); run;
Here's your problem. Each time the data set executes the current observation, it assigns a value to &yy and to &mm, and when it executes the last observation, this value for &yy and &mm is all that is available in future steps of your code.
If you want each observation of the data set to have it's own &yy and its own &mm then you probably need to have something like
and similarly adjust the calls to &yy later on in the code.
08-11-2017 01:02 PM
08-11-2017 01:06 PM
Page, the computations work such that the other vars are updated.
Could you please be specific about what you mean? What other variables are updated?
08-11-2017 01:19 PM
I don't see the relationship of resp_rate to your original question. As far as I can tell from looking at your code, I have provided an answer to your original question.
08-11-2017 01:47 PM
Need further help from the community? Please ask a new question.