DATA Step, Macro, Functions and more

Importing dataset using one dataset that has variables information

Reply
Occasional Contributor
Posts: 12

Importing dataset using one dataset that has variables information

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? Smiley Happy

 

Cheers,

 

Bruno

 

Super User
Posts: 5,257

Re: Importing dataset using one dataset that has variables information

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
Occasional Contributor
Posts: 12

Re: Importing dataset using one dataset that has variables information

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

 

 

Respected Advisor
Posts: 3,777

Re: Importing dataset using one dataset that has variables information

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;
Occasional Contributor
Posts: 12

Re: Importing dataset using one dataset that has variables information

[ Edited ]

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?

Respected Advisor
Posts: 3,777

Re: Importing dataset using one dataset that has variables information

[ Edited ]

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.

Super User
Posts: 10,516

Re: Importing dataset using one dataset that has variables information

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

Super User
Posts: 5,257

Re: Importing dataset using one dataset that has variables information

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
Occasional Contributor
Posts: 12

Re: Importing dataset using one dataset that has variables information

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.

Super User
Posts: 5,257

Re: Importing dataset using one dataset that has variables information

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
Occasional Contributor
Posts: 12

Re: Importing dataset using one dataset that has variables information

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

Super User
Posts: 17,861

Re: Importing dataset using one dataset that has variables information

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/

 

 

Occasional Contributor
Posts: 12

Re: Importing dataset using one dataset that has variables information

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 

Ask a Question
Discussion stats
  • 12 replies
  • 341 views
  • 5 likes
  • 5 in conversation