Michael A
Michael A

Reputation: 4615

How do I work with a SAS file that was created in a different format (Linux/Windows) if I don't have access to machine that created it?

I have numerous SAS datasets on my Windows 7 / SAS 9.4 machine:

data_19921.sas7bdat
data_19922.sas7bdat
data_19923.sas7bdat
....
data_200212.sas7bdat

etc. The format is data_YYYYM.sas7bdat or data_YYYYMM.sas7bdat (the latter for two digit months) and every dataset has identical variables and formatting. I'm trying to iterate over all of these files and append them into one big SAS dataset. The datasets were created on some Unix machine elsewhere in my company that I don't have access to. When I try to append the files:

%let root = C:\data;

libname in "&raw\in";
libname out "&raw\out";


/*****************************************************************************/

* initialize final data set but don't add any observations to it;
data out.alldata;
    set in.data_19921;
    stop;
run;

%macro append_files;
%do year=1992 %to 2002;
    %do month=1 %to 12;
        proc append data=out.alldata base=in.data_&year&month;
        run;
    %end;
%end;
%mend;

%append_files;

I get errors that say

File in.data_19921 cannot be updated because its encoding does not match the session encoding or the file is in a format native to another host, such as LINUX_32, INTEL_ABI

I don't have access to the Unix machine that created these datasets (or any Unix machine right now), so I don't think I can use proc cport and proc cimport.

How can I read/append these data sets on my Windows machine?

Upvotes: 0

Views: 1981

Answers (1)

Reeza
Reeza

Reputation: 21294

You can use the colon operator or dash to shortcut your process:

data out.alldata;
    set in.data_:;
run;

OR

data out.alldata;
    set in.data19921-in.data200212;
run;

If you have variables that are different lengths you may get truncation. SAS will warn you though: WARNING: Multiple lengths were specified for the variable name by input data set(s). This may cause truncation of data.

One way to avoid it is to create a false table first, using the original table. The following SQL code will generate the CREATE Table statements and you can modify the lengths manually as needed.

proc sql;
      describe table in.data19921;
quit;

*run create table statement here with modified lengths;

data out.alldata;
    set fake_data (obs=0)
       in.data19921-in.data200212;
run;

Upvotes: 3

Related Questions