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;
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.
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.
Thank you so much! This is my first time trying a macro code and your suggestions worked!
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.