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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 752 views
  • 0 likes
  • 3 in conversation