I was trying to create some macro to select the first non missing value for every variable of interest per subject. After sorting the data... %fstnmissvalue(dsn,var);
data temp..&var ;
set &dsn (keep=bene_id A0310F_ENTRY_DSCHRG_CD TRGT_DT rename=(TRGT_DT=&VAR._DT A0310F_ENTRY_DSCHRG_CD=&VAR._ENTRY_DSCHRG_CD)) ;
where &var ne . and &var ne "";
by bene_id;
if first.bene_id;
run;
%mend;
%macro fstnmissvalue_loop(varlist);
%let n1=%sysfunc(countw(&varlist));
%let dsn1=temp.mds_asmt11_sum;
%do i=1 %to &n1;
%let var1=%scan(&varlist, &i);
%fstnmissvalue(&dsn1,&var1);
%end;
%mend;
%fstnmissvalue_loop(G0110H1_EATG_SELF_CD G0110B1_TRNSFR_SELF_CD G0110I1_TOILTG_SELF_CD G0120A_BATHG_SELF_CD ); Notes from the log: 785 %fstnmissvalue(dsn,var);
-
180
WARNING: Apparent invocation of macro FSTNMISSVALUE not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
786 data temp..&var ;
-----
22
201
WARNING: Apparent symbolic reference VAR not resolved.
787 set &dsn (keep=bene_id A0310F_ENTRY_DSCHRG_CD TRGT_DT rename=(TRGT_DT=&VAR._DT
- ----------------------
214 79
23
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, /, ;, _DATA_, _LAST_, _NULL_.
ERROR 201-322: The option is not recognized and will be ignored.
ERROR 214-322: Variable name & is not valid.
ERROR 79-322: Expecting a =.
ERROR 23-7: Invalid value for the RENAME option.
-------
23
787! set &dsn (keep=bene_id A0310F_ENTRY_DSCHRG_CD TRGT_DT rename=(TRGT_DT=&VAR._DT
-------
214
787! A0310F_ENTRY_DSCHRG_CD=&VAR._ENTRY_DSCHRG_CD)) ;
WARNING: Apparent symbolic reference VAR not resolved.
WARNING: Apparent symbolic reference VAR not resolved.
ERROR 214-322: Variable name VAR._DT is not valid.
788 where &var ne . and &var ne "";
WARNING: Apparent symbolic reference VAR not resolved.
788 where &var ne . and &var ne "";
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference VAR not resolved.
WARNING: Apparent symbolic reference VAR not resolved.
ERROR: Syntax error while parsing WHERE clause.
789 by bene_id;
790 if first.bene_id;
791 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.VAR may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.VAR was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.03 seconds
ERROR: No matching %MACRO statement for this %MEND statement.
792 %mend;
793
794
795 %macro fstnmissvalue_loop(varlist);
796 %let n1=%sysfunc(countw(&varlist));
797 %let dsn1=temp.mds_asmt11_sum;
798 %do i=1 %to &n1;
799 %let var1=%scan(&varlist, &i);
800 %fstnmissvalue(&dsn1,&var1);
801 %end;
802 %mend;
803
804 /*%let dsn=temp.mds_asmt11_sum;*/
805 %fstnmissvalue_loop(G0110H1_EATG_SELF_CD G0110B1_TRNSFR_SELF_CD G0110I1_TOILTG_SELF_CD G0120A_BATHG_SELF_CD );
NOTE: Line generated by the invoked macro "FSTNMISSVALUE_LOOP".
1 %fstnmissvalue(&dsn1,&var1);
-
180
WARNING: Apparent invocation of macro FSTNMISSVALUE not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro FSTNMISSVALUE not resolved.
NOTE: Line generated by the invoked macro "FSTNMISSVALUE_LOOP".
3 %fstnmissvalue(&dsn1,&var1);
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro FSTNMISSVALUE not resolved.
NOTE: Line generated by the invoked macro "FSTNMISSVALUE_LOOP".
5 %fstnmissvalue(&dsn1,&var1);
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro FSTNMISSVALUE not resolved.
NOTE: Line generated by the invoked macro "FSTNMISSVALUE_LOOP".
7 %fstnmissvalue(&dsn1,&var1);
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
I have no idea where went wrong with my code. Is there any one that could help with my problem? I'll be very appreicated about your help. Thanks!!!
... View more