BookmarkSubscribeRSS Feed
jayanth_sas
Calcite | Level 5

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.

16 REPLIES 16
Jagadishkatam
Amethyst | Level 16

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
jayanth_sas
Calcite | Level 5

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.

art297
Opal | Level 21

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.

Jagadishkatam
Amethyst | Level 16

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
art297
Opal | Level 21

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.

Jagadishkatam
Amethyst | Level 16

Thank you Sir, i just noticed it.

Thanks,
Jag
jayanth_sas
Calcite | Level 5

Hi sir Arthur,

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

art297
Opal | Level 21

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.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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

art297
Opal | Level 21

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.

jayanth_sas
Calcite | Level 5

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.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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?

art297
Opal | Level 21

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

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thanks Arthur

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 16 replies
  • 1551 views
  • 4 likes
  • 5 in conversation