BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi

is there any possibility to change informats , while i am importing text file into datasets using proc import.

text file contains 300 variables.
2 REPLIES 2
Peter_C
Rhodochrosite | Level 12
although a variable can have only one informat declared in a data set, in a data step it can have a different informat every time it appears on an input statement.
With the INPUTN() function, it could have a different informat every time the function is executed!
Of course these levels of flexibility disappear in PROC IMPORT 😞

I recommend making the DATA STEP your friend.


PeterC
data_null__
Jade | Level 19
Assuming you are referring to TEXT files CSV, TXT etc. you can easily run PROC IMPORT and cut and paste the "generated code". Then you can change the informat by editing the existing INFORMAT statements. Or by adding additional statements, where you can use "SAS Variable Lists" to make short work of 300 variables. Or as was suggested you can modify the INPUT statement to include INFORMATS.

[pre]
data TEST;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile FT15F001 delimiter = ',' MISSOVER DSD firstobs=2 ;
informat a $1. ;
informat b $1. ;
informat c $1. ;
format a $1. ;
format b $1. ;
format c $1. ;

informat a--b $upcase1.; * added to change INFORMAT;
** NO need to bother the statements above unless the TYPE is changed.;

input
a $
b $
c $
;


if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
proc contents varnum;
proc print;
run;
[/pre]

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1072 views
  • 0 likes
  • 3 in conversation