I need to add total wood in overall total for each column. It does not work because “total” is character and cannot be placed in a numeric variable. Below is the code i am using:
proc sql; create table final as select year, count(distinct id) as total_persons, count(distinct case when age_cat = '20-25' then id end) as tot_20_25, count(distinct case when age_cat = '25-30' then id end) as tot_25_30, count(distinct case when age_cat = '30-35' then id end) as tot_30_35 from old_table group by year union all select 'Total',/*Here is line error, if i leave there just quotes works but it is not appropriate.*/ count(distinct id) as total_persons, count(distinct case when age_cat = '20-25' then id end) as tot_20_25, count(distinct case when age_cat = '25-30' then id end) as tot_25_30, count(distinct case when age_cat = '30-35' then id end) as tot_30_35 from old_table;
Advertisement
Answer
The problem is the type inconsistency. In SQL, you would fix this by converting the year
to a string:
cast(year as varchar(255))
In proc sql
, you can use put
:
put(year, 15.)