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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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";

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

Have you noticed the error message in log:

ERROR: Member yob2000.txt does not exist.

 

check the name(s) in the zip file.

romonysh
Obsidian | Level 7
Yeah I noticed the error, but I checked and that named file is in the zip. So I am still confused. Thank you for looking!
Shmuel
Garnet | Level 18

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";

Kurt_Bremser
Super User

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;
romonysh
Obsidian | Level 7
This also worked as a solution! thank you!