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 | |||||
# | Variable | Type | Len | Format | Label |
1 | Id2 | Num | 8 | BEST. | Id2 |
Alphabetic List of Variables and Attributes | |||||
# | Variable | Type | Len | Format | |
3 | S000 | Num | 8 | 3 | |
4 | SA01 | Num | 8 | 2 | |
5 | SA02 | Num | 8 | 3 | |
6 | SA03 | Num | 8 | 2 | |
7 | SE01 | Num | 8 | 2 | |
8 | SE02 | Num | 8 | 2 | |
9 | SE03 | Num | 8 | 2 | |
10 | SI01 | Num | 8 | 2 | |
11 | SI02 | Num | 8 | 2 | |
12 | SI03 | Num | 8 | 3 | |
13 | Year | Num | 8 | ||
2 | h_geocode | Num | 8 | 15 | |
1 | w_geocode | Num | 8 | 15 |
If both variables are numeric then don't convert one into a character string.
Just compare them.
Id2 = w_geocode
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.
What is that number 11 with a period after it doing there?
Its the format. 11 digits
It returns the same error without the format included
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.
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;
Yes. But the format for Id2 is 11. and w_geocode is 15.
@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?
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.
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.
@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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.