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;
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.
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;
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.
Thanks,
I have tried both format and length before input function and it also doens't solve the issue
Without some example data lines from the infile, we cannot test the code.
Try changing informat c_c $21.; to informat c_c $100.;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: