BookmarkSubscribeRSS Feed
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. I thought I had resolved this error yesterday but it has come back to haunt me.

Here's the code for my macro which runs without errors

%LET PATH = /folders/myfolders/takehometwo;
%LET define_len = SEX  RACERPI2  AGE_P ;   
LIBNAME new "&PATH";
* Step 2;
* Define the MACRO, it will unzip the file then label the 
  variables depending on which year the dataset represents;
%MACRO createset (first = , last = );
%do year = &first %to &last;   
	Filename ZIPFILE SASZIPAM "&PATH/adults&year..zip";
	data new.adults&year;
	INFILE ZIPFILE(SAMADULT.dat)  PAD LRECL=906;
	LENGTH &define_len 3;
	* Input for each column for emotions the datasets vary;
	input 
	 	RECTYPE       1 -   2   /* File type identifier */ 
	 	SRVY_YR       3 -   6   /* Survey year */
	 	HHX		$	  7 -  12
	 	FMX		$	 16 -  17
	 	FPX		$	 18 -  19
	 	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 */
		%if &year = 2010
		%then input  
		  SAD         372 - 372
	      NERVOUS     373 - 373    RESTLESS    374 - 374
	      HOPELESS    375 - 375    EFFORT      376 - 376
	      WORTHLS     377 - 377;
	 	%else %if &year = 2011 
	 	%then input
		  SAD         264 - 264
	      NERVOUS     265 - 265    RESTLESS    266 - 266
	      HOPELESS    267 - 267    EFFORT      268 - 268
	      WORTHLS     269 - 269;
	    %else %if &year = 2012 
	 	%then input
		  SAD         330 - 330
	      NERVOUS     331 - 331    RESTLESS    332 - 332
	      HOPELESS    333 - 333    EFFORT      334 - 334
	      WORTHLS     335 - 335;
	    %else %if &year = 2013 
	 	%then input
		  SAD         1002 - 1002
	      NERVOUS     1003 - 1003    RESTLESS    1004 - 1004
	      HOPELESS    1005 - 1005    EFFORT      1006 - 1006
	      WORTHLS     1007 - 1007;
	    %else %if &year = 2014 
	 	%then input
		  SAD         1067 - 1067
	      NERVOUS     1068 - 1068    RESTLESS    1069 - 1069
	      HOPELESS    1070 - 1070    EFFORT      1071 - 1071
	      WORTHLS     1072 - 1072;
	    %else %if &year = 2015 
	 	%then input
		  SAD         884 - 884
	      NERVOUS     885 - 885    RESTLESS    886 - 886
	      HOPELESS    887 - 887    EFFORT      888 - 888
	      WORTHLS     889 - 889
		;
run;
%end;
%mend createset;

When I call the macro for just the years 2010 and 2011 it doesnt give me any errors at all, but the 2010 dataset is a little strange. When I call any other year I get this error

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         %createset(first=2010, last=2015);
 
 NOTE: The infile library ZIPFILE is:
       Stream=/folders/myfolders/takehometwo/adults2011.zip
 
 NOTE: The infile ZIPFILE(SAMADULT.dat) is:
       File Name=SAMADULT.dat,
       Compressed Size=3125461,
       Uncompressed Size=27368606,
       Compression Level=-1,Clear Text=Yes
 
 NOTE: A total of 33014 records were read from the infile library ZIPFILE.
 NOTE: 33014 records were read from the infile ZIPFILE(SAMADULT.dat).
 NOTE: The data set NEW.ADULTS2010 has 33014 observations and 18 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.45 seconds
       cpu time            0.35 seconds
       
 
 
 NOTE: The infile library ZIPFILE is:
       Stream=/folders/myfolders/takehometwo/adults2012.zip
 
 NOTE: The infile ZIPFILE(SAMADULT.dat) is:
       File Name=SAMADULT.dat,
       Compressed Size=4379069,
       Uncompressed Size=37563200,
       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.ADULTS2011 may be incomplete.  When this step was stopped there were 0 observations and 18 variables.
 WARNING: Data set NEW.ADULTS2011 was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.03 seconds
       cpu time            0.02 seconds
       
 
 
 ERROR: Member SAMADULT.dat does not exist.
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set NEW.ADULTS2012 may be incomplete.  When this step was stopped there were 0 observations and 18 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.04 seconds
       cpu time            0.02 seconds
       
 
 
 ERROR: Member SAMADULT.dat does not exist.
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set NEW.ADULTS2013 may be incomplete.  When this step was stopped there were 0 observations and 18 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.03 seconds
       cpu time            0.01 seconds
       
 
 
 NOTE: The infile library ZIPFILE is:
       Stream=/folders/myfolders/takehometwo/adults2015.zip
 
 NOTE: The infile ZIPFILE(SAMADULT.dat) is:
       File Name=SAMADULT.dat,
       Compressed Size=451,Uncompressed Size=904,
       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.ADULTS2014 may be incomplete.  When this step was stopped there were 0 observations and 18 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.05 seconds
       cpu time            0.02 seconds
       
 
 74         
 75         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 ERROR: Invalid data length.
 FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.  Aborted during the INITIALIZE EXECUTION phase.
 WARNING: The data set NEW.ADULTS2015 may be incomplete.  When this step was stopped there were 0 observations and 18 variables.

Is this maybe because the .dat files in the zip are all called the same thing, so when it unzips the second one it gets called something like SAMADULT 2.zip?

 

Thank you very much for your time

3 REPLIES 3
Tom
Super User Tom
Super User

Why are you using SASZIPAM engine instead of the ZIP engine?

Are you sure that your ZIP file is valid?  Can you read it with a normal utility?

romonysh
Obsidian | Level 7

Thats a question I didnt ask myself. ZIP works a lot better than SASZIPAM. I no longer get any errors, and for some reason my adults2014 dataset is empty. I also am getting missing values for the emotion slots but the errors are gone for now.

 

Thank you!

Tom
Super User Tom
Super User

Make sure your macro is generating valid SAS code.

You seem to have missing semi-colons.

In a statement like this 

%if &x=1 %then input a b c;

the semi-colon ends the %IF/%THEN block. But the INPUT statement needs its own semi-colon.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 749 views
  • 1 like
  • 2 in conversation