Hi Guys,
I have these macro variables and have dataset
Count | Count1 | Coutn2 | |
Count_Start | 60 | 50 | 52 |
Have Dataset :
Count | Count1 | Coutn2 |
12 | 22 | 1 |
10 | 22 | 1 |
8 | 22 | 1 |
6 | 22 | 1 |
4 | 22 | 1 |
want dataset:
Count | Count1 | Coutn2 | |
12 | 22 | 1 | |
10 | 22 | 1 | |
8 | 22 | 1 | |
6 | 22 | 1 | |
4 | 22 | 1 | |
Sum | 40 | 110 | 5 |
Count_Start | 60 | 50 | 52 |
Remain | 20 | -60 | 47 |
data have_c; input Count Count1 Count2; cards; 12 22 1 10 22 1 8 22 1 6 22 1 4 22 1 ; run; %let Count_t =60; %let Count1_t =50; %let Count2_t=52; proc sql; select ' ' as x label='#',* from have_c union all select 'sum',sum(count) , sum(count1), sum(count2) from have_c union all select 'Count_Start',&count_t,&count1_t,&count2_t from have_c(obs=1) union all select 'Remain',&count_t-sum(count) , &count1_t-sum(count1), &count2_t-sum(count2) from have_c; quit;
Before we go very far on this what will the result be used for? It is generally a very bad idea to include summary values inside a data set as it is very possible for someone to run a procedure on the data and include those values as input.
Does the result need to be a data set or is this a report?
And what have you attempted so far?
I will use this dataset for my report. i wanted it as dataset if possible
I have tried this but this is giving column wise not row wise
data have_c;
input Count Count1 Count2;
cards;
12 22 1
10 22 1
8 22 1
6 22 1
4 22 1
run;
proc sql noprint;
select sum(count) , sum(count1), sum(count2) into: sum_count, :sum_count1, :sum_count2
from have_c;
quit;
%let Count_t =60;
%let Count1_t =50;
%let Count2_t=52;
data have2;
set have_c;
remain1 = &Count_t - &sum_count;
remain2 = &Count1_t - &sum_count1;
remain3 = &Count2_t - &sum_count2;
run;
proc print;
run;
data have_c; input Count Count1 Count2; cards; 12 22 1 10 22 1 8 22 1 6 22 1 4 22 1 ; run; %let Count_t =60; %let Count1_t =50; %let Count2_t=52; proc sql; select ' ' as x label='#',* from have_c union all select 'sum',sum(count) , sum(count1), sum(count2) from have_c union all select 'Count_Start',&count_t,&count1_t,&count2_t from have_c(obs=1) union all select 'Remain',&count_t-sum(count) , &count1_t-sum(count1), &count2_t-sum(count2) from have_c; quit;
@KsharpThanks alot
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.