Hello, I am learning to use SAS with SAS studio via a virtual machine on a mac. I am learning how to use macros, and am trying to use a macro to unzip a file. The program ran with no problem, the shared folders were able to be accessed, yet the output didnt provide anything.
Here is my code
dm 'clear log';
Options nocenter nodate nonumber symbolgen;
%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)
Ive attached the zip file and my log when I run it. I should be getting data sets for the years 2000-2005, instead I get empty data sets
Cheking the zip file there are two subfolders.
Why not extract the files from the zipped folder, then the filename should be:
"&path/names/names/yob2000.txt";
Have you noticed the error message in log:
ERROR: Member yob2000.txt does not exist.
check the name(s) in the zip file.
Cheking the zip file there are two subfolders.
Why not extract the files from the zipped folder, then the filename should be:
"&path/names/names/yob2000.txt";
Rule #1 for macro development: start with code that works for a single, non-dynamic instance. Then use macro language to make the code dynamic.
This worked for me:
filename zipfile zip '/folders/myfolders/names.zip';
data dsn1997;
infile zipfile(names/yob1997.txt) dlm=",";
input name $ gender $ number;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.