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

Hi all,

I just started learning SAS a few months ago and am currently learning macro. I have a zip file and I made sure the file is in my virtual machine file (since I am running university edition on Mac). The macro program ran with no problem yet it could not read any of the data in the file. Hope some could help me out thanks!

 

Options nocenter nodate nonumber nosymbolgen;
%Let Path = c:/folders/myshortcuts/myFolder/;
Libname MYFOLDER '/folders/myfolders';
%macro readraw (first=, last=);
Filename ZIPFILE SASZIPAM '&Path/names.zip';
   %do year=&first %to &last;
	 DATA MYFOLDER.DSN&Year;
 	    INFILE ZIPFILE(yob&year..txt) DLM=',';
  	    INPUT name $ gender $ number;
	 RUN;
	 title "Listing from Data Set (Newborns' Names) for &Year";
	    proc print data=MYFOLDER.DSN&Year(obs=5) noobs; 
		format number comma7.;
        run;
    %end ;
%mend readraw;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

There are two obvious issues with the code as posted.

One is a simple SAS programming mistake.  Macro references (& and %) are not evaluated inside of strings that are using single quote characters on the outside. Use double quote characters instead.

"&Path/names.zip"

Second is that the virtual machine cannot see your file system.  It can only see the folder you shared (and any folder and files under it).  So if you mapped the folder on your MAC named 

/Users/me/my_SAS_Stuff

to the unix path on the virtual machine named:

/folders/myfolders

Then in your SAS code ALL of the paths that you use must start with:

/folders/myfolders

So you need change the value you assign to the PATH macro variable to reflect this.  It cannot start with c: like in your code. 

 

If you are not sure where SAS sees the files you can ask it by looking at the path in the properties of the file in the FILES and FOLDERS view.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

There are two obvious issues with the code as posted.

One is a simple SAS programming mistake.  Macro references (& and %) are not evaluated inside of strings that are using single quote characters on the outside. Use double quote characters instead.

"&Path/names.zip"

Second is that the virtual machine cannot see your file system.  It can only see the folder you shared (and any folder and files under it).  So if you mapped the folder on your MAC named 

/Users/me/my_SAS_Stuff

to the unix path on the virtual machine named:

/folders/myfolders

Then in your SAS code ALL of the paths that you use must start with:

/folders/myfolders

So you need change the value you assign to the PATH macro variable to reflect this.  It cannot start with c: like in your code. 

 

If you are not sure where SAS sees the files you can ask it by looking at the path in the properties of the file in the FILES and FOLDERS view.

cheungmonica
Calcite | Level 5

Thank you so much! This is my first time trying a macro code and your suggestions worked!

Siwen
Calcite | Level 5
Options nocenter nodate nonumber nosymbolgen;
%Let Path =/folders/myfolders;
Libname mylib "&Path";
%macro readraw (first=, last=);
  Filename ZIPFILE SASZIPAM "&Path/names.zip";
   %do year=&first %to &last;
	 DATA mylib.DSN&Year;
 	    INFILE ZIPFILE(yob&year..txt) DLM=',';
  	    INPUT name $ gender $ number;
	 RUN;
	 title "Listing from Data Set (Newborns' Names) for &Year";
	    proc print data=mylib.DSN&Year(obs=5) noobs; 
		format number comma7.;
        run;
    %end ;
%mend readraw;
%readraw(first=2000, last=2005);

Here is my code using in SAS U.E. I put the names.zip in /folders/myfolders. But it still has a problem that SAS cannot find the .txt file. I don't know how to fix it.

Could you please figure out how I can correct it?

 

Thank you so much.

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 901 views
  • 0 likes
  • 3 in conversation