SAS Programmers: I spent an inordinate amount of time troubleshooting a “simple” problem of changing the length of a character variable in SAS. Even though I found a solution, I’m still befuddled and hoping someone here can explain. A data set was imported from a CSV file via Proc Import per the following: %Macro ReadCSV (infile , outfile );
PROC IMPORT OUT= &outfile
DATAFILE= &infile
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
GUESSINGROWS=200;
run;
%Mend ReadCSV; Note that GUESSINGROWS was initially set to 75. Maximum character length of the values for the variable Company was 12, which appeared after line 75 in the table. SAS truncated the variable names to 8 characters, as reported by Proc Contents: I tried changing the length in a subsequent data step: data a;
length Company $12;
format Company $12.;
set a;
run; Proc Contents returned the following attributes: That didn’t help. When printed, variable names for Company were still truncated at 8 characters. Then I tried the following Proc SQL code: proc sql;
alter table work.a
modify Company char(12) format=$12. informat=$12.;
quit; Proc Contents returned the following attributes: Even though this shows Length, Format, and Informat attributes with 12 characters, printed variable names for Company were still truncated @ 8 characters. After some hair pulling, I went back and changed the GUESSINGROW value from 75 to 200 in Proc Import and re-ran the code. Proc Contents returned the following attributes: This changed the character value from 8 to 12, printing just as I wanted. However, except for the variable number, these attributes are identical to that obtained via Proc SQL! Even when the GUESSINGROWS statement was deleted, I couldn’t effect any change in printed character length using the above data step or Proc SQL code regardless of what Proc Contents was showing. Can anyone explain what’s going on here? Are there different syntax rules for changing the length of a character variable in a user programmed data step or in Proc SQL subsequent to Proc Import vs. reading data via the Input statement? Thank you in advance.
... View more