Hi all,
Today when I run the code as below:
data np_parks;
set pg2.np_final;
putlog "NOTE:START DATASTEP ITERATION"
keep Region ParkName AvgMonthlyVisitors Acres Size;
LENGTH Size $6.;
where Type="PARK";
PUTLOG tYPE;
format AvgMonthlyVisitors Acres comma10.;
Type=propcase(Type);
AvgMonthlyVisitors=sum(DayVisits,Campers,OtherLodging)/12;
if Acres<1000 then Size="Small";
else if Acres<100000 then Size="Medium";
else Size="Large";
PUTLOG='CONTENT';
run;
In the original datasetpg2.np_final, there is no column for Size, so Size just being written to PDV after the compilation progress going through all the data statement in this data step. I am wondering why it causes an error in the log as below
56 data np_parks; 57 set pg2.np_final; 58 putlog "NOTE:START DATASTEP ITERATION" 59 keep Region ParkName AvgMonthlyVisitors Acres Size; 60 LENGTH Size $6.; ERROR: Character length cannot be used with numeric variable Size. 61 where Type="PARK"; 62 PUTLOG tYPE; 63 format AvgMonthlyVisitors Acres comma10.; 64 Type=propcase(Type); 65 AvgMonthlyVisitors=sum(DayVisits,Campers,OtherLodging)/12; 66 if Acres<1000 then Size="Small"; 67 else if Acres<100000 then Size="Medium"; 68 else Size="Large"; 69 PUTLOG='CONTENT'; 70 run;
It is quite clear to me that Size is a character rather than a numeric variable.
Thank you!
Because there is no semicolon after
putlog "NOTE:START DATASTEP ITERATION"
Hi @qoit
The first few lines of the input are as below
And could you please let me know why I should change from length to format. Because length is to assign the length for a variable in the PDV while format just for displaying purpose. I am wondering you are mentioning informat rather than format?
Thank you.
Because there is no semicolon after
putlog "NOTE:START DATASTEP ITERATION"
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.
Ready to level-up your skills? Choose your own adventure.