Obs year id ldmk side cycle extreme time 1 2013 BZ01 L1 L 1 max 436 2 2013 BZ01 L1 L 1 min 567 3 2013 BZ01 L1 L 2 max 697
4 2013 BZ01 L1 L 2 min 821
5 2013 BZ01 L1 L 3 max 946
%macro forceL(d1,d2,id, year,ldmk, side, cycle);
data _null_;
set &d1 ;
where (id=&id and ldmk=&ldmk) & (side=&side & cycle = &cycle);
if extreme= "max" then call symput('maxtime', time);
if extreme= 'min' then call symput('mintime', time);
run;
data force1;
set &d2 (where = (( ltime ge &maxtime and ltime le &mintime) & (id = &id and ldmk=&ldmk))) ;
disp=0 ; force=0 ; velocity=0 ; acc=0;
if _n_ = 1 then baseZ = Ldisp ;
if _n_ = 1 then baseF = Lforce ;
Retain baseZ basef;
if _n_ > 1 then disp= BaseZ - Ldisp ;
if _n_ > 1 then force=Lforce-baseF;
if _n_ > 1 then velocity = (dif(disp)/dif(Ltime))*100 ;
if _n_ > 2 then acc = (dif(velocity)/dif(Ltime))*100;
run;
*more sas codes to calculate required stats;
%mend;
Let me try again to explain my problem.I have two datasets, d1, d2 and I pasted head of d1 here. I have to extract the information of time from d1, for the combinations of id, ldmk, year, side, cycle and use that information to extract rows from d2 data and run some stats on those subsets of datasets, but I have a large number of combinations of columns in d1 and I am trying to programmatically do that. Else I have to make so many macro calls. and in the macro I pasted here, this works only when values of id are passed such as "BZ01" , ldmk as"L1" and so on as all are character variable except cycle and time.
So I was trying to test a piece of code to extract the id, ldmk , side year combination in one go, but I am failing. Can you please suggest the correct way to extract the information in do loop ?
I tried following codes in a small dataest to extract relevant rows of data and I am failing.
%let id="BZ01" "BZ02";
%let side="L";
%let ldmk= "L1" "L2";
data p;
set endpts;
where ((id=%qscan(%bquote(&id),2) and ldmk=%qscan(%bquote(&ldmk),2))) and (year="2013" and side="L"));
RUN;
Log
582 data p; 583 set endpts; 584 where ((id=%qscan(%bquote(&id),2) and ldmk=%qscan(%bquote(&ldmk),2))) and (year="2013" and 584! side="L")); NOTE: Line generated by the macro function "QSCAN". 2 "BZ02" - 22 76 ERROR: Syntax error while parsing WHERE clause. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, (, *, +, -, :, INPUT, NOT, PUT, ^, ~.
ERROR 76-322: Syntax error, statement will be ignored.
585 RUN;
... View more