BookmarkSubscribeRSS Feed
Konkordanz
Pyrite | Level 9

Hey,

 

is there a SAS-Command for inserting a single row (proc report)? Something like that:

Insert a row before the value "X" of Variable "Z". In the Column of variable Z write the Text "(X+A)/2". Write the result of this formular in the cell of Variable Car.

 

Have:

Var_ZCAR
G3
J5
T2
E4
X2
A1
Q

3

 

 

Want:

Value ZCAR
G3
J5
T2
E4
(X+A)/21,5
X2
A1
Q3

 

Maybe with the _break_ - command? would be great to get a hink for solving my problem. Thank you very much!

 

6 REPLIES 6
tarheel13
Rhodochrosite | Level 12
Can’t you just add it to the dataset that you feed in to proc report?
Konkordanz
Pyrite | Level 9

Thx for answering!

Hmm...you mean: Add a new observation to the data? Could work. But I dont know the command for adding a new row (observation) into my base dataset.Can you give me a hink how I can implement it with my formular? Just a hink... 😉 Thank you!

Konkordanz
Pyrite | Level 9

Sorry for the double-post. But I want to concretize my questiion.

 

This is the table I have:

 

data have;
input Year Konto Amount;
datalines;
2019 6011 15
2019 6011 20
2019 6012 21
2019 6012 30
2019 73 18
2019 73 23
2019 6011 25
2020 6011 36
2019 6012 14
2020 6012 25
2020 73 17
2020 6011 69
2020 6011 32
2020 6012 14
2020 6012 78
2020 73 22
; run;

 

 

YearKontoamount
2019601115
2019601120
2019601221
2019601230
20197318
20197323
2019601125
2020601136
2019601214
2020601225
20207317
2020601169
2020601132
2020601214
2020601278
20207322

 

The aim is a new table "want" with summarized group by "Year" and "Konto". To summarize it there are 2 different formulars:

 

First Observation of the new Table shall get the konto-name "Reals". This is the sum of the amount of "6011" + "6012"

Second observation of the new table shall get the name "Steu". This is the Result of (the sum of 6011) minus (the sum of 73).

 

want:

JahrKontoamount
2019Reals125
2020Reals254
2019Steu19
2020Steu142

 

Would be great to get some help. I tried it for hours and it still doesnt work. Thank you!

tarheel13
Rhodochrosite | Level 12

142 does not look correct for Steus in 2020, not according to your specification. The sum of 6011 for year 2020 is 137. The sum of 73 for year 2020 is 39. 137-39 = 98, not 142.

tarheel13
Rhodochrosite | Level 12
proc sql number;
	select year, 'Reals' as konto, sum(amount) as amount
		from have
		where konto in (6011,6012)
		group by year
		
	union all 
	select year, 'Steus' as konto, sum(amount) as amount
		from
	(select year, 'Steus' as konto, sum(amount) as amount
		from have
		
		where konto=6011
		group by year
	union all	
	select year, 'Steus' as konto, -1*sum(amount) as amount
		from have
		where konto=73
		group by year)
			group by year;
quit;

This will do what you asked for but as I said, 142 is not correct given your definition and data you posted.

Konkordanz
Pyrite | Level 9

Okay Thank you, Ill try it! 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1400 views
  • 1 like
  • 2 in conversation