BookmarkSubscribeRSS Feed
nrb
Fluorite | Level 6 nrb
Fluorite | Level 6

I have the following dataset: who's inputs are CustomerID, SaleDate,Variety, Quantity 

240W 02-07-2008 Ginger 120
240W 02-07-2008 Protea 180
356W 02-08-2008 Heliconia 60
356W 02-08-2008 Anthurium 300
188R 02-11-2008 Ginger 24
188R 02-11-2008 Anthurium 24
240W 02-12-2008 Heliconia 48
240W 02-12-2008 Protea 48
356W 02-12-2008 Ginger 240

 

 I have to Write a procedure to compute the average quantity of sale. I then have to Write a DATA step to put the average quantity in a macro variable AVG, I cant use the %let statement. Run the program below.

        proc chart data = flowersales;

        vbar variety / type=mean sumvar=quantity ref=&avg; run;

 

How would I do this? I can't figure it out, please help me understand how it would work. 

3 REPLIES 3
Reeza
Super User

The steps are outlined. 

 

First create the procedure to calculate the average - PROC MEANS

Secomd, create a macro variable in a data step - CALL SYMPUTX() 

 

Given the phrasing here, I suspect this is a homework assignment so I won't write the code for you.  

sachin01663
Obsidian | Level 7
First write the data step to get average into a variable. This can be done by Proc SQL AVG function or by Proc Means. Then you use the two ways to ask SAS to automatically add this into Macro:

By CallSymput routine
By Into: Statement in Proc SQL

Both the methods are explained here with examples:

https://analyticswithsas.blogspot.co.uk/2014/08/sas-macros-for-beginners.html?m=1
Astounding
PROC Star

I would suggest a slightly different strategy.  Since you need a DATA step to create a macro variable, let the DATA step compute the average value as well.  Here is the idea:

 

data _null_;

set have (keep=quantity) end=nomore;

where quantity > .;

tot_quantity + quantity;

if nomore then do;

   * Divide TOT_QUANTITY by number of observations;

   * Transfer the result to a macro variable AVG;

end;

run;

 

The details are up to you.

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