BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DThielemier
Calcite | Level 5

 

My raw data has four variables (Item number, Grouping, Part code, Quote). 

 

Item numberGroupingPart codeQuote
3328Group AA 
3328Group BA 
3328Group CA 
3328Group DA 
3328Group EA 
3328Group FA2197.98
3328Group GA 
3328Group HA 
3328Group AB 
3328Group BB 
3328Group CB 
3328Group DB1446
3328Group EB1540.59
3328Group FB1318.89
3328Group GB1432.21
3328Group HB1501.54
3328Group AC 
3328Group BC 
3328Group CC 
3328Group DC 
3328Group EC 
3328Group FC1729.77
3328Group GC 
3328Group HC 
3328Group AD 
3328Group BD 
3328Group CD 
3328Group DD1966
3328Group ED1976.61
3328Group FD1787
3328Group GD1989.17
3328Group HD 

 

I used a proc tabulate statement to display the quote data, by part code, for each combination of item number and grouping.

 

image.png

 

From here, I need to calculate some new variables.  I need a new part code that is derived by subtracting part code B from part code D, for all item number and grouping combinations.  Can I calculate new variables within proc tabulate? 

I'd be fine with calculating the data directly from the raw data, but I don't know how to tell SAS "subtract quote value for Part code D, item number 3328, group C from part code B, item number 3328, group C". 

 

Any advice would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Agreeing with @Reeza, there is no point in using a PROC TABULATE here. It doesn't do what you want, and it doesn't advance the process.

 

I'd be fine with calculating the data directly from the raw data, but I don't know how to tell SAS "subtract quote value for Part code D, item number 3328, group C from part code B, item number 3328, group C". 

 

I think a PROC TRANSPOSE followed by doing the calculation you describe in a data step ought to work just fine.

 

Something like this:

 

UNTESTED CODE

proc transpose data=have out=have_t;
    by item_number grouping;
    var quote;
    id part_code;
run;

data want;
    set have_t;
    result=b-d;
run;

If you want actual TESTED code, you need to provide the data as actual SAS data step code.

--
Paige Miller

View solution in original post

3 REPLIES 3
Reeza
Super User
You cannot do this with PROC TABULATE. You may be able to with PROC REPORT, but I wouldn't recommend it at this stage. You can use the OUT= option on PROC TABULATE to push your results to a data set and then use that data set in a data step to do the actual calculations.
PaigeMiller
Diamond | Level 26

Agreeing with @Reeza, there is no point in using a PROC TABULATE here. It doesn't do what you want, and it doesn't advance the process.

 

I'd be fine with calculating the data directly from the raw data, but I don't know how to tell SAS "subtract quote value for Part code D, item number 3328, group C from part code B, item number 3328, group C". 

 

I think a PROC TRANSPOSE followed by doing the calculation you describe in a data step ought to work just fine.

 

Something like this:

 

UNTESTED CODE

proc transpose data=have out=have_t;
    by item_number grouping;
    var quote;
    id part_code;
run;

data want;
    set have_t;
    result=b-d;
run;

If you want actual TESTED code, you need to provide the data as actual SAS data step code.

--
Paige Miller
DThielemier
Calcite | Level 5

Transpose worked great!  Thank you for the recommendation!  I'm still pretty new to SAS, so thanks for helping me learn a new proc!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1316 views
  • 2 likes
  • 3 in conversation