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.
....

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 2885 views
  • 3 likes
  • 3 in conversation