BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kumarK
Quartz | Level 8

 

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
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;



View solution in original post

4 REPLIES 4
ballardw
Super User

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?

kumarK
Quartz | Level 8

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;

Ksharp
Super User

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;



kumarK
Quartz | Level 8

@KsharpThanks alot

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1338 views
  • 1 like
  • 3 in conversation