BookmarkSubscribeRSS Feed
michokwu
Quartz | Level 8

Hi. Any reason why I am getting this error. Both variables are numeric

 

proc sql;
create table my_location as
select Id2,
sum(s000) as s000,
sum(sa01) as sa01,
sum(sa02) as sa02,
sum(sa03) as sa03,
from work, tracts
where Id2 = put(w_geocode, 11.)
;
quit;

 

Proc content output below:

Alphabetic List of Variables and Attributes
#VariableTypeLenFormatLabel
1Id2Num8BEST.Id2
      
      
      
      
Alphabetic List of Variables and Attributes 
#VariableTypeLenFormat 
3S000Num83 
4SA01Num82 
5SA02Num83 
6SA03Num82 
7SE01Num82 
8SE02Num82 
9SE03Num82 
10SI01Num82 
11SI02Num82 
12SI03Num83 
13YearNum8  
2h_geocodeNum815 
1w_geocodeNum815 
12 REPLIES 12
Tom
Super User Tom
Super User

If both variables are numeric then don't convert one into a character string.

Just compare them.

 Id2 = w_geocode

 

michokwu
Quartz | Level 8

changed it to: 

where Id2 = w_geocode 11.

error: 

ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, AND, EQ, EQT,
EXCEPT, GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=,
|, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

Tom
Super User Tom
Super User

What is that number 11 with a period after it doing there?

michokwu
Quartz | Level 8

It returns the same error without the format included

Tom
Super User Tom
Super User

Post the text from the log using the Insert Code button in the forum editor to preserve the formatting of the text so that SAS's indication of where it got confused is preserved.

Note that there is no way (or reason) to attach a format to a boolean expression such as the one in your WHERE clause.

Tom
Super User Tom
Super User

Looks like you are trying to run this query.

Right.

proc sql;
create table my_location as
  select work.Id2
       , sum(tracts.s000) as s000
       , sum(tracts.sa01) as sa01
       , sum(tracts.sa02) as sa02
       , sum(tracts.sa03) as sa03
  from work
     , tracts
  where work.Id2 = tracts.w_geocode
;
quit;
michokwu
Quartz | Level 8

Yes. But the format for Id2 is 11. and w_geocode is 15.

 

Tom
Super User Tom
Super User

@michokwu wrote:

Yes. But the format for Id2 is 11. and w_geocode is 15.

 


It does not matter how the number is displayed when comparing two numbers.  5 is the same as 5 whether you write it with 10 leading spaces or 14.

 

Are you saying the VALUES are different?  If so how are they different?  Do you need to divide the geocode value by 10,000?  If so then what if the last four digits are not all zeros?

michokwu
Quartz | Level 8

I am using proc sql to create a table which aggregates variables into w_geocodes by Id2

I think the format is important if it has to be done properly.

 

If you can propose a different method, that will be great.

 

Thank you.

Tom
Super User Tom
Super User

If you want to attach a different format to a variable then do that in the variable list part of the SELECT statement.

select id2 format=15., ....

Or in this case since you are joining on equality just keep the variable that has the right format attached since both variables have to have the same value for the equality test to be true.

 

But it really seems you do not understand what a format is.  It is just instructions for how you want the values displayed. It does not change the value at all.  SAS only has two data types.  Floating point numbers and fixed length character variables.

Tom
Super User Tom
Super User

@michokwu wrote:

I am using proc sql to create a table which aggregates variables into w_geocodes by Id2

I think the format is important if it has to be done properly.

 

If you can propose a different method, that will be great.

 

Thank you.


Perhaps the issue is that the query you posted does not match what you actually want to do?  Can you post a simple set of example input data and what output summary you want to get for that sample data?

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
  • 12 replies
  • 1050 views
  • 0 likes
  • 2 in conversation