Help using Base SAS procedures

Proc import

Reply
Occasional Contributor
Posts: 13

Proc import

I have a flat file of 1000 observations and 50 variables. I can able to directly extract this by proc import procedure but how can we assign formats to this data? Do we have any thing while importing can we assign length, data type, label? Can any one suggest me on this plz.

Trusted Advisor
Posts: 1,131

Re: Proc import

you can try to import the data using the data step instead of the proc import procedure, incase if you wish to control the formats, length etc., of the variables.

Something like below,

data want;    

     infile "~path/test.csv";

     informat  ....;

     format .......;

     input variables name .............;

run;

Thanks,

Jagadish

Thanks,
Jag
Occasional Contributor
Posts: 13

Re: Proc import

Hi jagadish,

Yeah we can do the same in infile if you have few variables, if variable list is 100 , 200 then using infile is tedious na.

PROC Star
Posts: 7,364

Re: Proc import

Immediately after running proc import press function key F4.  That will give you the code that was run and you can modify all of the formats and informats as desired and then rerun the modified code.

Trusted Advisor
Posts: 1,131

Re: Proc import

Hi Sir,

I tried to import a sample data by proc import in sas 9.2 and after execution by default in the log it displayed the back end datastep it executed for proc import.

So probably for sas version less than 9.2 we need to use the function f4 to get the same.

Thanks,

Jagadish

Thanks,
Jag
PROC Star
Posts: 7,364

Re: Proc import

It is the same with all of the SAS versions.  The log displays the code that was run, but pressing function key f4 inserts that code into your editor.

Trusted Advisor
Posts: 1,131

Re: Proc import

Thank you Sir, i just noticed it.

Thanks,
Jag
Occasional Contributor
Posts: 13

Re: Proc import

Hi sir Arthur,

Thank you very much for your advice let me try this and come back to you.

PROC Star
Posts: 7,364

Re: Proc import

Of Note: Don't expect the proc generated code to be optimal, well written code.  IT WON'T BE!  When you press F4 you will get the exact code that the proc submits, but the proc-generated code has numerous macro variables and checks that don't have to be there, and uses separate format and informat statements for every variable.  Obviously, getting rid of the fluff and taking advantage of variable lists can make the code a lot easier to maintain.

Super Contributor
Super Contributor
Posts: 440

Re: Proc import

Hi Arthur,'

so  if i importing a file

proc import datafile='C:\Users\x\Desktop\SAS Files\test.xls' out=new replace;
run;

and after running this code when i pres the F4 i get the same code as above

Can you please explaing this below ? Smiley Happy

"The log displays the code that was run, but pressing function key f4 inserts that code into your editor."

PROC Star
Posts: 7,364

Re: Proc import

Ah, this is the first time (that I know of at least) that you mentioned you were importing an Excel workbook.  All of my suggestions were based on the (apparently wrong) assumption that you were importing a text or delimited file.

Occasional Contributor
Posts: 13

Re: Proc import

Hi arthur,

The abobe comment is passed by some one (Tal) else and the suggestions you have provided earlier is for the correct purpose only i.e text or delimited file.

Thank you.

Super Contributor
Super Contributor
Posts: 440

Re: Proc import

sorry about the confusion Arthur. So the F4 key function works only with text files and does the import data wizard has the ability of changing  format as you import the file,probably not?

PROC Star
Posts: 7,364

Re: Proc import

Tal: You really ought to start a new discussion rather than trying to piggyback onto an existing one.

However, while I don't think proc import lets you control formats and informats, the excel libname engine does.  Take a look at http://books.google.ca/books?id=QOI_xTgWwgsC&pg=PA35&lpg=PA35&dq=import+excel+libname+engine+format+...

and, specifically, search that file for DBTYPE

Super Contributor
Super Contributor
Posts: 440

Re: Proc import

thanks Arthur

Ask a Question
Discussion stats
  • 16 replies
  • 562 views
  • 4 likes
  • 5 in conversation