BookmarkSubscribeRSS Feed
brunosm
Obsidian | Level 7

Hi,

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? 🙂

 

Cheers,

 

Bruno

 

12 REPLIES 12
LinusH
Tourmaline | Level 20

Exporting the data using PROC CPORT will preserve almost all metadata information about the table alongside with the data.

What is the application?

Data never sleeps
brunosm
Obsidian | Level 7

Hi LinusH,

 

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...

 

Thanks,

 

Bruno

 

 

data_null__
Jade | Level 19

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;
brunosm
Obsidian | Level 7

Hi data_null__,

 

sorry for my ignorance but... how can I use what you wrote in the importation process?

 

Can you give me an example plz?

data_null__
Jade | Level 19

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

INPUT (_ALL_)(:);

 

And instead of writing the generated code to the SASLOG you would write it to a file and %INC it to execute it.

ballardw
Super User

How are exporting the data sets currently? CPORT should write to any File reference that Proc Export or a data step does.

LinusH
Tourmaline | Level 20
Why do you want to switch from a newer server based SAS environment to a local older one?
Still, CPORT is somewhat backward compatible, so why don't give it a try?
Data never sleeps
brunosm
Obsidian | Level 7

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.

LinusH
Tourmaline | Level 20

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.

Data never sleeps
brunosm
Obsidian | Level 7

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

Reeza
Super User

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.

http://blogs.sas.com/content/sasdummy/2012/12/06/copy-files-in-sas-eg/

 

 

brunosm
Obsidian | Level 7

Hi again,

 

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!

 

Cheers,

 

Bruno 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 1241 views
  • 5 likes
  • 5 in conversation