BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ResoluteCarbon
Obsidian | Level 7

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12


Because there is no semicolon after

putlog "NOTE:START DATASTEP ITERATION"

View solution in original post

4 REPLIES 4
qoit
Pyrite | Level 9
Can you change the LENGTH statement to FORMAT? I am not sure why the error unless I see the first few observations of the input data set.
ResoluteCarbon
Obsidian | Level 7

Hi @qoit 

The first few lines of the input are as below

ResoluteCarbon_0-1617341348459.png

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.

japelin
Rhodochrosite | Level 12


Because there is no semicolon after

putlog "NOTE:START DATASTEP ITERATION"
ResoluteCarbon
Obsidian | Level 7
OMG, disaster!
Thank you @japelin . I just notice the character and numeric and forget the syntax error.
....

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3857 views
  • 3 likes
  • 3 in conversation