BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
romonysh
Obsidian | Level 7

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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 seconds

I have tried a few things online and couldn't get it to work, thank you very much!

 


 

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

romonysh
Obsidian | Level 7
Hey Kurt, thanks for responding. I fixed that error and the other errors persist.
Reeza
Super User

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 seconds

I have tried a few things online and couldn't get it to work, thank you very much!

 


 

romonysh
Obsidian | Level 7
Awesome this worked great! The code works fine for the year 2011 but not for 2010, leading me to suspect the problem is with my 2010 dataset and not with the code.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1546 views
  • 3 likes
  • 3 in conversation