BookmarkSubscribeRSS Feed
c1991
Fluorite | Level 6

I have a piece of code that has infile, informat then input steps after which allocations happens on the file that has been imported.

However, one of the fields is read in as informat C_C $21. and input C_C $

In the output file, the field is cut off and doesn't have enough characters, I am not sure how to change the format for the output to not cut off. i have tried adding format straight after informat but before input, however, this doens't make any difference.

 

data CHARGE_DETAIL_&billing_month;
    %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
 infile "&path\MCB_Raw\charge_detail_&billing_month..csv"
 delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
        informat c_c $21.;
        informat cust_name $35.
    input
        c_c $
        cust_name $
    ;

    if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
    run;

data CHARGE_DETAIL_&billing_month(drop= billing_monthx billing_year);
format cust_name $35. billing_month ddmmyy10.;
    set CHARGE_DETAIL_&billing_month(rename=(billing_month=billing_monthx));
billing_month = input('01'||billing_monthx||compress(billing_year), date9.);
proc sort data= CHARGE_DETAIL_&billing_month;
by billing_month;
run;
7 REPLIES 7
Kurt_Bremser
Super User

Your code can't really work as posted; the second informat statement lacks a closing semicolon.

Please post the real code you ran, the log, and some lines from the infile that illustrate what is being cut off.

c1991
Fluorite | Level 6

Apologies,

 

It has a semicolon. The code runs successfully, but cuts this field short.

data CHARGE_DETAIL_&billing_month;
    %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "&path\MCB_Raw\charge_detail_&billing_month..csv"
delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
		informat c_c $21.;
		informat cust_name $35.;
	input
		c_c $
		cust_name $
	;

    if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
    run;
data CHARGE_DETAIL_&billing_month(drop= billing_monthx billing_year);
format cust_name $35. billing_month ddmmyy10.;
	set CHARGE_DETAIL_&billing_month(rename=(billing_month=billing_monthx));
billing_month = input('01'||billing_monthx||compress(billing_year), date9.);
proc sort data= CHARGE_DETAIL_&billing_month;
by billing_month;
run;
Astounding
PROC Star

Before the INPUT statement, try adding:

 

length c_c $ 21;

 

If that doesn't fix it, it's because the data itself contains commas that should become part of C_C.  That would require a different change.

c1991
Fluorite | Level 6

Thanks,

 

I have tried both format and length before input function and it also doens't solve the issue

Miracle
Barite | Level 11

Try changing  informat c_c $21.; to informat c_c $100.; 

Tom
Super User Tom
Super User

The second data step is referencing variables that your first data step that reads the CSV file is not creating. 

Perhaps your real problem lies there and not in the reading of the text file.

 

Your import step looks like it was either generated by PROC IMPORT or copied from the code that PROC IMPORT generates.  The code that PROC IMPORT generates generally works, but it is not really very good code to use for modeling your own data step. You do not need to specify either an INFORMAT or a FORMAT for character variable. Just define the length that you want them to have.  In general you only need INFORMAT for Date/Time variables or numeric variables that include commas and dollar signs in the text file.  You only need to attach FORMATs to Date/TIme varaibles. You can attach formats to numeric variable if you want to make the values display better for you.  For example if your values are large you might want to use COMMA (or DOLLAR) format so that it will be easier to users to read the results when SAS prints the values.

 

data CHARGE_DETAIL_&billing_month;
  infile "&path\MCB_Raw\charge_detail_&billing_month..csv"
    DSD DLM=',' TRUNCOVER lrecl=32767 firstobs=2 
  ;
  length c_c $21 cust_name $35 ;
  input c_c -- cust_name ;
run;

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
  • 7 replies
  • 1645 views
  • 0 likes
  • 5 in conversation