- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, im in a class in university where I am learning to use SAS. I am trying to read data from a zipped file using a macro, and then labelling the data. I am using SAS Studio on a mac.
OPTIONS LS=160 PS=79 NODATE FORMCHAR="|----|+|---+=|-/\<>*" PAGENO=1; %LET PATH = /folders/myfolders/takehometwo; FILENAME MYLOG "&PATH/SPD_log.TXT"; FILENAME MYPRINT "&PATH/SPD_OUTPUT.TXT"; LIBNAME new "&PATH"; %let define_len = SEX RACERPI2 AGE_P ; * create the MACRO to read the first few sets; %MACRO createset (first = , last = ); * Call the data set; Filename ZIPFILE SASZIPAM "&PATH/adults&year..zip"; %do year = &first %to &last; data new.adult&Year; INFILE ZIPFILE(SAMADULT.dat) PAD LRECL=906; LENGTH &define_len 3; input RECTYPE 1 - 2 /* File type identifier */ SRVY_YR 3 - 6 /* Survey year */ WTFA_SA 27 - 32 /* Final weight */ STRAT_P 34 - 36 /* Pseudo-stratum for PUF variance estimation */ PSU_P 37 - 38 /* Pseudo-PSU for PUF estimation */ SEX 39 RACERPI2 42 - 43 /* OMB groups w/multiple race */ AGE_P 48 - 49 /* Age reported */ SAD 372 - 372 NERVOUS 373 - 373 RESTLESS 374 - 374 HOPELESS 375 - 375 EFFORT 376 - 376 WORTHLS 377 - 377 ; run; %end; %mend createset; %createset(first=2010, last=2011);
Here is the code, when I run it I get this error:
WARNING: Apparent symbolic reference YEAR not resolved. NOTE: The infile library ZIPFILE is: Stream=/folders/myfolders/takehometwo/adults&year..zip NOTE: The infile ZIPFILE(SAMADULT.dat) is: File Name=SAMADULT.dat, Compressed Size=2,Uncompressed Size, Compression Level=-1,Clear Text=No ERROR: Invalid data length. FATAL: Unrecoverable I/O error detected in the execution of the DATA step program. Aborted during the INITIALIZE EXECUTION phase. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set NEW.ADULT2010 may be incomplete. When this step was stopped there were 0 observations and 14 variables. WARNING: Data set NEW.ADULT2010 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
I have tried a few things online and couldn't get it to work, thank you very much!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is your option statement correct and needed? That would be for listing output, but SAS Studio has HTML as the default output?
You need to move the FILENAME statement within the DO loop. You're referencing the YEAR macro variable before it's been created.
Filename ZIPFILE SASZIPAM "&PATH/adults&year..zip"; *Using it before it has been created; %do year = &first %to &last; data new.adult&Year; INFILE ZIPFILE(SAMADULT.dat) PAD LRECL=906;
@romonysh wrote:
Hi, im in a class in university where I am learning to use SAS. I am trying to read data from a zipped file using a macro, and then labelling the data. I am using SAS Studio on a mac.
OPTIONS LS=160 PS=79 NODATE FORMCHAR="|----|+|---+=|-/\<>*" PAGENO=1; %LET PATH = /folders/myfolders/takehometwo; FILENAME MYLOG "&PATH/SPD_log.TXT"; FILENAME MYPRINT "&PATH/SPD_OUTPUT.TXT"; LIBNAME new "&PATH"; %let define_len = SEX RACERPI2 AGE_P ; * create the MACRO to read the first few sets; %MACRO createset (first = , last = ); * Call the data set; Filename ZIPFILE SASZIPAM "&PATH/adults&year..zip"; %do year = &first %to &last; data new.adult&Year; INFILE ZIPFILE(SAMADULT.dat) PAD LRECL=906; LENGTH &define_len 3; input RECTYPE 1 - 2 /* File type identifier */ SRVY_YR 3 - 6 /* Survey year */ WTFA_SA 27 - 32 /* Final weight */ STRAT_P 34 - 36 /* Pseudo-stratum for PUF variance estimation */ PSU_P 37 - 38 /* Pseudo-PSU for PUF estimation */ SEX 39 RACERPI2 42 - 43 /* OMB groups w/multiple race */ AGE_P 48 - 49 /* Age reported */ SAD 372 - 372 NERVOUS 373 - 373 RESTLESS 374 - 374 HOPELESS 375 - 375 EFFORT 376 - 376 WORTHLS 377 - 377 ; run; %end; %mend createset; %createset(first=2010, last=2011);Here is the code, when I run it I get this error:
WARNING: Apparent symbolic reference YEAR not resolved. NOTE: The infile library ZIPFILE is: Stream=/folders/myfolders/takehometwo/adults&year..zip NOTE: The infile ZIPFILE(SAMADULT.dat) is: File Name=SAMADULT.dat, Compressed Size=2,Uncompressed Size, Compression Level=-1,Clear Text=No ERROR: Invalid data length. FATAL: Unrecoverable I/O error detected in the execution of the DATA step program. Aborted during the INITIALIZE EXECUTION phase. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set NEW.ADULT2010 may be incomplete. When this step was stopped there were 0 observations and 14 variables. WARNING: Data set NEW.ADULT2010 was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.09 seconds cpu time 0.03 secondsI have tried a few things online and couldn't get it to work, thank you very much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your first problem is this:
WARNING: Apparent symbolic reference YEAR not resolved.
Fix it first by defining macro variable year with a proper value, as found in the name of the zip file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is your option statement correct and needed? That would be for listing output, but SAS Studio has HTML as the default output?
You need to move the FILENAME statement within the DO loop. You're referencing the YEAR macro variable before it's been created.
Filename ZIPFILE SASZIPAM "&PATH/adults&year..zip"; *Using it before it has been created; %do year = &first %to &last; data new.adult&Year; INFILE ZIPFILE(SAMADULT.dat) PAD LRECL=906;
@romonysh wrote:
Hi, im in a class in university where I am learning to use SAS. I am trying to read data from a zipped file using a macro, and then labelling the data. I am using SAS Studio on a mac.
OPTIONS LS=160 PS=79 NODATE FORMCHAR="|----|+|---+=|-/\<>*" PAGENO=1; %LET PATH = /folders/myfolders/takehometwo; FILENAME MYLOG "&PATH/SPD_log.TXT"; FILENAME MYPRINT "&PATH/SPD_OUTPUT.TXT"; LIBNAME new "&PATH"; %let define_len = SEX RACERPI2 AGE_P ; * create the MACRO to read the first few sets; %MACRO createset (first = , last = ); * Call the data set; Filename ZIPFILE SASZIPAM "&PATH/adults&year..zip"; %do year = &first %to &last; data new.adult&Year; INFILE ZIPFILE(SAMADULT.dat) PAD LRECL=906; LENGTH &define_len 3; input RECTYPE 1 - 2 /* File type identifier */ SRVY_YR 3 - 6 /* Survey year */ WTFA_SA 27 - 32 /* Final weight */ STRAT_P 34 - 36 /* Pseudo-stratum for PUF variance estimation */ PSU_P 37 - 38 /* Pseudo-PSU for PUF estimation */ SEX 39 RACERPI2 42 - 43 /* OMB groups w/multiple race */ AGE_P 48 - 49 /* Age reported */ SAD 372 - 372 NERVOUS 373 - 373 RESTLESS 374 - 374 HOPELESS 375 - 375 EFFORT 376 - 376 WORTHLS 377 - 377 ; run; %end; %mend createset; %createset(first=2010, last=2011);Here is the code, when I run it I get this error:
WARNING: Apparent symbolic reference YEAR not resolved. NOTE: The infile library ZIPFILE is: Stream=/folders/myfolders/takehometwo/adults&year..zip NOTE: The infile ZIPFILE(SAMADULT.dat) is: File Name=SAMADULT.dat, Compressed Size=2,Uncompressed Size, Compression Level=-1,Clear Text=No ERROR: Invalid data length. FATAL: Unrecoverable I/O error detected in the execution of the DATA step program. Aborted during the INITIALIZE EXECUTION phase. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set NEW.ADULT2010 may be incomplete. When this step was stopped there were 0 observations and 14 variables. WARNING: Data set NEW.ADULT2010 was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.09 seconds cpu time 0.03 secondsI have tried a few things online and couldn't get it to work, thank you very much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content