BookmarkSubscribeRSS Feed
Konkordanz
Pyrite | Level 9

Hi,

 

I want to create a new variable within the proc-report-command.

 

The first aim is: for every Land and year it should sum the Euro-amount. Each country can occur more than once. Until now my table contents following Variables:

The Var land should be the group-var of column A.

The Var Jahr contents 2019 and 2020. 2019 is column B und 2020 is column C.

The Var betrag_t is the analysisvariable in Euro.

 

This first aim works with this code:

 

proc report Data=test
column land Jahr, betrag_t;
define land / group;
define Jahr / across "01.01. - 31.12." style={cellwidth=3 cm};
define betrag_t  / analysis "1.000 €" sum Format=16.2;
run;

The Result:

 

land20192020
1…€…€
2

 

The second aim is my problem: I want to create a new variable and I dont know how to do that.

In my base dataset there is also the variable bev. These contains the population size of each land. The new variable with the name je_Einw  should be the result of the formel: betrag_t/bev. (€ per Person)

The final aim is a table like this:

 

Land201920202020 - per person
1…€…€…€
2

 

I tried it many times...but it doesnt work. For example with this code:

 

proc report Data=test;
column land Jahr je_Einw, betrag_t;
define land /group "Art der Zahlg";
define Jahr /across "01.01. - 31.12." style={cellwidth=3 cm};
define betrag_t /analysis "1.000 €" sum Format=16.2;
define je_Einw / computed;
compute je_Einw;
je_Einw=betrag_t/bev;
endcomp;
run;

The Error says:

 

ERROR: There is more than one ANALYSIS usage associated with
the column defined by the following elements.
Name Usage
-------------------------------- --------
je_Einw       COMPUTED
Betrag_t      ANALYSE

Im a newbe in SAS but I really want to learn it. Therefore I need some help. Would be awesome to get some 🙂 Thank you!!

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Can you provide a portion of data set TEST as a SAS data step? Please follow these instructions: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

--
Paige Miller
Konkordanz
Pyrite | Level 9

Thx for answering! This would be problematic, cause my dataset contains secret data.

Basically it would be very helpful, to get just one solution for the follow question:

 

I need a macro-order in the head of the code, that put out a specific value of the base dataset. This value should be integrated in my formular. Something like this:

 

Data Test;
set FILE_XY;
Betrag_t=betrag/1000;
%let EXAMPLE (bev=if Sitz=... & Jahr=2020)²
run;

proc report Data=test;
column land Jahr je_Einw, betrag_t;
define land /group "Art der Zahlg";
define Jahr /across "01.01. - 31.12." style={cellwidth=3 cm};
define betrag_t /analysis "1.000 €" sum Format=16.2;
define je_Einw / computed;
compute je_Einw;
je_Einw=betrag_t/&EXAMPLE;
endcomp;
run;

² Definition: I dont know, how to use a makro-order like this...the Example-Value that has to be integrated in the formular is coupled to a if-condition. This prder means: Take the value of the Variable bev if the variable Sitz= XY and the Variable Jahr=2020. Is this possible with the %let-Order?

PaigeMiller
Diamond | Level 26

Make up some data, where every variable has a random value (or even, every variable has a value of 1)

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 1019 views
  • 0 likes
  • 2 in conversation