BookmarkSubscribeRSS Feed
Afor910327
Obsidian | Level 7

I am not very good in SAS and would like to know what is going on with the code below, could someone explain me as simple as possible what is going on? 

 

Essentially, I am having issues in aggregating everything correctly, I do not know why in data io3_&currioyr, none of the aggregate are being aggregated; however, in data io1_&currioyr and data io2_&currioyr, everything is fine...

Thanks a lot!

 

 

%macro price_series;
	%do currioyr = &b_ioyear %to &e_ioyear;

/* io1 is current dollar output for the previous year, (Pt-1*Qt-1) */

data io1_&currioyr;
set itemoutput2;
if basingyear=%eval(&currioyr-1) and ioyear=%eval(&currioyr-1);
*if basingyear=&previoyr. and ioyear=&previoyr.;
io1_proval=proval;
drop pi proval basingyear ioyear;

/* io2 is current dollar output for the current year, (Pt*Qt)*/

data io2_&currioyr;
set itemoutput2;
if basingyear=&currioyr. and ioyear=&currioyr.;
io2_proval=proval;
drop pi proval basingyear ioyear;

/* io3 is simply the price ratio (Pt/Pt-1), PI column from the itemoutput table */

data io3_&currioyr;
set itemoutput2;
if basingyear=%eval(&currioyr-1) and ioyear=&currioyr.;
io3_pi=pi;
drop basingyear ioyear proval pi;

run;
5 REPLIES 5
Tom
Super User Tom
Super User

I don't see any code that is doing any aggregation. 

 

Just some filtering via a subsetting IF and coping one variable into another via an assignment statement.

 

If the 2nd and 3rd work and the 1st doesn't then perhaps the variable you are copying from is not on the input dataset for that step?

 

Run your macro with the MPRINT option and carefully review that code that it generates and runs. Perhaps there is a typo somewhere that will be easier to see in the log then in the source code.

PaigeMiller
Diamond | Level 26

Why do you say it is supposed to be "aggregating"? Aggregating what?

 

Is your question "what is going on" meaning what does the code do? Or does your question "what is going on" mean: why isn't it aggregating? Or does your question "what is going on" mean something else?

--
Paige Miller
Afor910327
Obsidian | Level 7

Paige so I basically need to know what is going on, essentially I have some variables that from the first and second data sets are no being imported to the third data set. Those variable are the aggregates. 

 

My apologies for not being clear and thank you!

Tom
Super User Tom
Super User

@Afor910327 wrote:

Paige so I basically need to know what is going on, essentially I have some variables that from the first and second data sets are no being imported to the third data set. Those variable are the aggregates. 

 

My apologies for not being clear and thank you!


You are running three data steps. Each one is reading from the same source.  So of course anything done in the first or second step is not reflected in the third step since it is again reading from the same unmodified input.

 

You need to explain what you are trying to do.  Perhaps you can just do it all in one data step.

PaigeMiller
Diamond | Level 26

@Afor910327 wrote:

Paige so I basically need to know what is going on, essentially I have some variables that from the first and second data sets are no being imported to the third data set. Those variable are the aggregates. 

 

My apologies for not being clear and thank you!


I'm afraid this doesn't make anything clearer.

 

Exactly why are you using the word "aggregates" or "aggregating" here? What is supposed to be aggregating? Where in the code is the aggregating supposed to happen?

 

What is your question that you keep repeating the phrase "what is going on"?

 

In other words, provide a lot more details.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 548 views
  • 1 like
  • 3 in conversation