Here is my code. As shown, I'm trying to process the macro only by ID, so that the last defined ID processed doesn't overwrite the previous. filename dirlist pipe "dir /B &dir\*.csv";
DATA dirlist ;
length csvname $30;
infile dirlist length=reclen;
input csvname $varying30. reclen;
call symput ('num_files',_n_);
id= scan(csvname,1,'_');
RUN ;
**DO THIS MACRO FOR EACH ID**;
**note: there are multiple files per ID ;
%macro GAscoring;
%do i=1 %to &num_files ;
DATA _null_;
set dirlist; *if _n_=&i;
call symput('filein',csvname);
call symput('id',id);
RUN;
DATA DATA_IMPORT;
LENGTH
datetimestamp $ 23
x 8
y 8
z 8
lux 8
event 8
temp 8 ;
LABEL
datetimestamp = "F1"
x = "F2"
y = "F3"
z = "F4"
lux = "F5"
event = "F6"
temp = "F7" ;
FORMAT
datetimestamp $CHAR23.
x BEST7.
y BEST7.
z BEST7.
lux BEST3.
event BEST3.
temp BEST4. ;
INFORMAT
datetimestamp $CHAR23.
x BEST7.
y BEST7.
z BEST7.
lux BEST3.
event BEST3.
temp BEST4. ;
INFILE "&dir\&filein" LRECL=32760 ENCODING="WLATIN1" TERMSTR=crlf DLM=',' MISSOVER firstobs=101 DSD ;
INPUT
datetimestamp : $23.
x : ?? BEST7.
y : ?? BEST7.
z : ?? BEST7.
lux : ?? BEST3.
event : ?? BEST3.
temp : ?? BEST4. ;
RUN;
DATA DATA_RAW1; set DATA_IMPORT;
id= "&id";
date = input(scan(datetimestamp,1,' '), yymmdd10.); format date mmddyys10. ;
timestamp = (input(substr(datetimestamp,12,8),time8. )
+ (input(substr(datetimestamp,21,3),3.))/1000); format timestamp time12.3 ;
newdatetimestamp = dhms(date,0,0,timestamp) ; format newdatetimestamp datetime21.3 ;
timestamp = floor(timestamp);
drop datetimestamp ;
rename newdatetimestamp = datetimestamp ;
drop date timestamp ;
run;
DATA surveydata ;
set sleeplog.surveydata ;
beddatetime = lag(beddatetime) ; format beddatetime datetime21.9 ;
output surveydata ;
RUN ;
PROC SQL;
CREATE TABLE SLEEPWINDOW AS
SELECT t1.x, t1.y, t1.z, t1.lux, t1.temp, t1.id, t1.datetimestamp,
t2.day, t2.beddatetime, t2.wakedatetime, t2.sleep_h
FROM WORK.DATA_RAW1 t1
NATURAL JOIN surveydata t2
WHERE t1.datetimestamp BETWEEN t2.wakedatetime AND t2.beddatetime
ORDER by id, datetimestamp ;
QUIT;
PROC APPEND data= sleepwindow out= SLEEP_&id ;
RUN ;
**APPEND HAS TO ONLY APPEND sleepwindow FOR SAME IDs;
%end ;*of do num_files;
%mend GAscoring(&id); %GAscoring;
... View more