BookmarkSubscribeRSS Feed
new_sas_user_4
Quartz | Level 8

Hi everyone,

 

Could you please help me calculate a row for MTD calculations

Eg: If I am at Day_no 4 , I want the first row to say Audi MTD 720 18 1620 62

 

Below is the sample data:

data raw_Data;
length brand $4;
input brand Day_No CM_Units CM_sales PM_Units PM_sales;
datalines;
Audi 1 100 2 200 3
Audi 2 200 10 400 50
Audi 3 20 2 500 3
Audi 4 400 4 520 6
;

 

Thank you !!

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Eg: If I am at Day_no 4 , I want the first row to say Audi MTD 720 18 1620 62

 

Do you mean you want the 4th row to say Audi MTD 720 18 1620 62

 

Why does it have to be in any particular row?

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Do you want to create a new data set or Is this for reporting purposes?

new_sas_user_4
Quartz | Level 8

It is for reporting purposes...I would eventually use it in proc report

In the proc report, the first row will be "MTD"

and if Its day_no 4 , the PM_units and PM_sales might still have numbers, but I want the MTD based on if the CM_Sales and CM_units are non-zero.

 

data raw_Data;
length brand $4;
input brand Day_No CM_Units CM_sales PM_Units PM_sales;
datalines;
Audi 1 100 2 200 3
Audi 2 200 10 400 50
Audi 3 20 2 500 3
Audi 4 400 4 520 6
Audi 5 0 0 566 2
Audi 6 0 0 250 25
Audi 7 0 0 200 2
Audi 8 0 0 200 2
;

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