I try to import a selection of ZIPPED CSV files into SAS BASE 9.4. This is working file by file, but I would like to import all CSV files named like "AXAMCE" followed by any other character.
I have working code for 1 file, but the ZIP contains also other file which I'd like to read beginning with the same characters "AXAMCE"
How to read all CSV files in the ZIP beginning with AXAMCE.D1905 into 1 SAS file?
infile ziplib("AXAMCE.D190524.T0210.CSV") firstobs =2 ;
Related
I have a PowerShell program that searches a folder on my PC for several text files. If the file is not in the folder, it writes the filename to another text file. When the procedure finishes, I have a text file with a list of files (one column) that are missing from the folder.
Next I would like PC SAS to read the list from the text file and launch the corresponding SAS program that I have already written that retrieves each file from our FTP server.
I am not sure how to go about having SAS read the filenames and launch my FTP programs. Any suggestions on how to accomplish this task?
Sounds like the first problem is you need to modify the SAS program to use a dataset with the list of filenames to process. One easy way to do that is to create a macro that downloads one file and takes the filename as an input parameter. So convert your code that downloads a file to a macro.
%macro mf_download(file);
* Code that downloads &FILE from mainframe. ;
%mend ;
Then it is easy to write a program that reads the names from a file and calls the macro for each name in the file. So say the file with the list of names if named filelist.txt then that part of the program might look like this:
data names;
infile 'filelist.txt' truncover ;
input filename :$256. ;
call execute(cats('%nrstr(%mf_download)(',filename,')'));
run;
I have a sas7bdat format file, but it's zipped.
I could unzip the file and work on it, but this makes me lose hard disk space and time.
So I tried this code on SAS :
filename myfile ZIP 'C:\...\data.zip' member="data.sas7bdat" ;
data yoyo;
infile myfile (data.sas7bdat);
input;
put _infile_;
run;
But I get an empty yoyo table in the WORK library.
How can I successfully import the data.sas7bdat ?
Thank you,
You need to uncompress the dataset before SAS can use it. So you need to find a place that has enough space for the fully expanded file.
Note that your code is trying to specify the member name of the file within the ZIP file twice. You should only do that once. Either point the fileref to the aggregate location and use member name in the reference. Or point the fileref to the individual member and just use the fileref.
Here is a method to expand the file into your current WORK folder.
%let member=data.sas7bdat;
filename in zip 'C:\...\data.zip' member="&member" recfm=n;
filename out "%sysfunc(pathname(work))/&member" recfm=n;
data _null_;
rc=fcopy('in','out');
run;
You can now work with the file using the name WORK.DATA.
proc print data=work.data(obs=1); run;
If you want to read data from a ZIP file directly then it either needs to be raw (text) data or in a streaming format, like a SAS V5 XPORT file.
I was given a list of files that need to be imported into SAS, however I am struggling to import them correctly. The files are formatted as such:
There is one "Header File" that contains a few lines of metadata followed by:
RECORD 1
Header column 1
Header column 2
Header column 3
Header column 4
Record 2
Header column 1
Header column 2
Header column 3
Header column 4
Header column 5
Header column 6
.
.
.
RECORD 3
.
.
.
And then "data files" which contain no meta data (that I am aware of) and are simply column ("|") delineated.
I was told these files were generated using SAS and I believed them to be a library, however:
Proc CIMPORT data="C..."
did not work.
I can import them individually using
Proc Import data="";
DBMS=DLM;
Run;
I asked this question earlier to no avail, I included more information this time. I feel like this is something that is really easy that I am just missing somehow. Thank you very much in advance.
You can use PROC IMPORT to read the pipe delimited files. Use the getnames=no; statement to tell it to generate its own names. You can then use the metadata from the first file to generate RENAME statements to change the names.
PROC CIMPORT is for reading transport files generated by PROC CPORT.
For a more complete example with code please post some actual examples of the data files, especially the one with the metadata. If the metadata is complete then you could probably skip the PROC IMPORT and just use the metadata to directly write data steps to read the data files.
I am writing a file to csv before reading it into Stata. How do i specify missing values in the csv file, so that when the csv is read into Stata they are automatically coded by as missing?
Found answer - if values are set as . in the csv file, they are read into stata as missing values.
I have to read csv files every day which are kept in a folder with a date time stamp on it. eg: newfolder20150430023210
I have to extract these files everyday from the folder. But since the folder has got time stamp on it, I'm unable to create a macro which can read the latest file from the directory. I could create a macro of the current datetime but not the folder datetime.
eg: path:- D:\SAS\Data\Newfolder20150430023210\file.csv I need to read this path where 20150430023210 is dynamic.
thank you
I think you need to find the newest folder first, this code wil do that:
filename f pipe "dir /B/A:D/O:-D D:\SAS\Data\Newfolder*";
data _null_;
infile f;
input;
call symputx("lastDir",_infile_);
stop;
run;
Now, you have a macrovariable "lastDir" that has the name of the folder.