01-15-2016 10:59 AM
I need a little help in exporting and importing some datasets.
I have some tables in a library called MYDBS which were exported into a local pc folder as .tab files.
This tables have different variables and different types of variables, which can be numeric, strings or dates. So, I decided to also export an aditional table that contains all the information about all the variables in all tables (in MYDBS library). I have done the following code:
proc contents data= MYDBS._all_ noprint out=varsDesc; run;
Now I was thinking if it would be possible to import those .tab files, considering the variables types, formats and informats of each variable that are available in the varsDesc table...
I don't need to import all the tables at once, I can import one by one. I just want to preserve the original variables types, formats and informats.
Can anyone help me?
01-15-2016 11:05 AM
Exporting the data using PROC CPORT will preserve almost all metadata information about the table alongside with the data.
What is the application?
01-15-2016 11:19 AM
I think that won't be possible, I will try to explain why.
I'm exporting the datasets using SAS Guide 5.1. I'm working in a remote server (linux), and I'm saving the files into a windows folder, so I have to use the export wizard (i think that it won't be possible to use PROC CPORT or any kind of "code").
Then, I want to import the .tab files into SAS Guide 4, which I use localy. And that's why I'm having trouble in preserve variables types and formats.
BTW, I can do it if I export into .mdb files, but I would like to save some space and time...
01-15-2016 11:52 AM
You can use the information from PROC CONTENTS to write code.
proc contents noprint data=sashelp.cars out=contents; run; proc sort data=contents; by libname memname varnum; run; proc print; run; data _null_; set contents; by libname memname; if first.memname then do; put 'data ' memname '(label=' memlabel:quote. ');'; end; put +3 'Attrib ' name 'length=' @; if type eq 2 then put '$' @; put length @; if not missing(format) then do; format=cats(format,formatl,'.',formatd); put format= @; end; if not missing(informat) then informat=cats(INFORMAT,INFORML,'.',INFORMD); else if not missing(format) then informat=format; if not missing(informat) then put informat= @; if not missing(label) then put label=$quote. @; put ';'; if last.memname then do; put +3 'Run;'; end; run;
01-15-2016 12:04 PM - edited 01-15-2016 12:05 PM
sorry for my ignorance but... how can I use what you wrote in the importation process?
Can you give me an example plz?
01-15-2016 12:11 PM - edited 01-15-2016 12:13 PM
If you had exported the files to TAB delimited and you can make an association between the file name and data set name you could continue the program I wrote to write the INFILE statement needed to refer to the external file and INPUT statement need to read the records. If you exported the data in VARNUM order then the input statement would be simple as
And instead of writing the generated code to the SASLOG you would write it to a file and %INC it to execute it.
01-15-2016 11:55 AM
How are exporting the data sets currently? CPORT should write to any File reference that Proc Export or a data step does.
01-15-2016 12:07 PM
01-15-2016 12:26 PM
It's not that i dont want, it's because i have restricted access.
I cant export anything unless i use the export wizard... i cant assign a libname in my computer for example.
01-15-2016 12:36 PM
Don't you have write access to any folder on the server? If you have, CPORT....!
Have you tried to export as SAS data set, the SAS data file format hasn't changed (much) between the versions you are mentioning.
01-15-2016 12:48 PM
No, i don't have permission to do that.
Only way to export: Right click --> "Export <table> as a Step In Project..."
I cant do it because it says that I have to have the same version installed localy
01-15-2016 02:08 PM
I think the point @Linus is trying to make is you should be able to export a CPORT file to the server, in some location that you have access to and then FTP or move them over a different way. You can usually ssh or ftp into the server via winscp but it's not a straightforward process and your IT may have turned off access somehow.
That being said there's an EG add-in that would allow you to move files from the server.
01-20-2016 07:05 AM
First of all, thank you all for your help!
Second, I've done it! I found a different (and easier) approach to this problem.
In SAS Guide 5.1, there is an option under the Tasks menu, Data > Download Data Files to PC... that allows to save sas datasets in a local directory.
It's a very easy way to export multiple tables, it's very fast and all variable types and formats are safe because it is exported to a sas dataset.
Then, in SAS Guide 4, I just have to do a simple import procedure.
Thank you all again!