BookmarkSubscribeRSS Feed
souji
Obsidian | Level 7

Hi,

Another one, Please correct me, if I am wrong

#5- do not know how to get it

 

/*Scenario:

1.Souj.input24a contains 2 variables, Product and Qty for 20 transactions

2.Souj.input24b contains 2 variables, Product and Price for 20 transactions

3.Create output dataset results.output24

4.Merge data sets Souj.input24a and Souj.input24b one-to-one in order to calculate a new variable

totalprice(=Qtr*Price) for each observation

5. what is the grand total totalprice for the product='screwdriver'?

6.what is the average(mean) totalprice for product='Tape'? */

 

proc sort data=Souj.input24a out=out.input24a;

by product;

run;

proc sort data=Souj.input24b out=out.input24b;

by product;

run;

data results.output24;

merge out.input24a out.input24b;

by product;

totalPrice=gty*price;

run;

proc means data=results.output24;

by product;

where product='Tape';/* I think #6)

run;

 

 

8 REPLIES 8
ed_sas_member
Meteorite | Level 14

Hi @souji 

At first sight it seems that proc means should be:

proc means data=results.output24 mean;
var totalprice;
where product='Tape';
run;

There is also a typo -> gty should be replaced by qty in your code

 

The very first thing to do would be to try your code!

You will easily see if the syntax is correct and if you get the right results (especially in this case, as there are very few variables and observations).

souji
Obsidian | Level 7

Hi @ed_sas_member

 

Thank you for your quick response, I appreciate you

 

What about :  5. what is the grand total totalprice for the product='screwdriver'?

 

please help me this too

Souji

ed_sas_member
Meteorite | Level 14
Hi @souji,
You’re welcome!
For question 5, I believe you are asked to compute the sum of totalprice of screwdrivers.
An easy way to do that is to use a proc print :
Proc print data=results.output24;
Sum totalprice ;
Where product = ‘screwdriver’;
Run;

You can also use a proc means -> change mean by sum in your code and adapt the condition where.

Best
Mona4
Calcite | Level 5

IN QUESTION

Merge data sets Souj.input24a and Souj.input24b one-to-one in order to calculate a new variable

totalprice=(Qtr*Price) for each observation

 

one-to-one merge (using without by statement)

match merge(using by statement)

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/basess/n11fri54im86d4n1imc3rzeeffyt.htm#:~:te...

please can some one explain????????

PaigeMiller
Diamond | Level 26

What part of the documentation do you need an explanation for? Please be specific.

--
Paige Miller
Mona4
Calcite | Level 5
*difference between One-to-one merging and match merging*

Souj.input24a contains 2 variables, Product and Qty for 20 transactions
2.Souj.input24b contains 2 variables, Product and Price for 20 transactions
3.
*Create output dataset results.output24 4.Merge data
sets Souj.input24a and Souj.input24b one-to-one in order to calculate a new
variable*
totalprice(=Quantity*Price) for each observation
5. what is the grand total totalprice for the product='screwdriver'?
6.what is the average(mean) totalprice for product='Tape’?
Mona4
Calcite | Level 5

Souj.input24a contains 2 variables, Product and Qty for 20 transactions
2.Souj.input24b contains 2 variables, Product and Price for 20 transactions
3.Create output dataset results.output24
4.Merge data sets Souj.input24a and Souj.input24b one-to-one in order to calculate a new variable
totalprice(=Quantity*Price) for each observation
5. what is the grand total totalprice for the product='screwdriver'?
6.what is the average(mean) totalprice for product='Tape’?

PaigeMiller
Diamond | Level 26

What part of this are you having trouble with? Can you show us the code you have tried so far?

--
Paige Miller

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
  • 8 replies
  • 2032 views
  • 1 like
  • 4 in conversation