-1

I have SAS dataset as in the attached picture.. what I'm trying to accomplish is created new calculated field from Total column where I'm subtracting first row-second row, third row-fourth row and so on..

What i have tried so far is

DATA WANT2;
SET WANT;
BY APPT_TYPE;
IF FIRST.APPT_TYPE THEN SUPPLY-OPEN; ELSE 'ERROR';
RUN;

this throws an eror as statement is not valid..

not really sure how to go about this

My dataset

  • Please post the text of your data into the question, not photographs. Your picture looks like the output of PROC TRANSPOSE. Wouldn't it be easier to do the subtraction before transposing the data? Perhaps you could include in your example data what the original dataset looked like before transposing? – Tom Jan 02 '20 at 19:34
  • @Tom thanks for the feedback Tom. The reason i transposed because i wanted to get total across rows first, not sure how to do that in proc sql.. After transposing then I ran the array function to get the total across rows then i got stuck here. – user168836 Jan 02 '20 at 21:01

1 Answers1

0

Here you go. The best I can do with the limited information you provided. Next time please provide sample data and your expected output.

data have;
input APPT_TYPE$ _NAME_$ Quantity;
datalines; 
ASON Supply 10
ASON Open 8
ASSN Supply 9
ASSN Open 7
S30 Supply 11
S30 Open 8
;

proc sort data = have;
    by APPT_TYPE descending _NAME_ ;
run;

data want;
    set have;
    by APPT_TYPE descending _NAME_;

    lag_N_Order = lag1(Quantity);
    N_Order = Quantity;
    Difference = lag_N_Order - N_Order;

    keep APPT_TYPE _NAME_ N_Order lag_N_Order Difference Type;
    if last.APPT_TYPE & last._NAME_ & Difference>0;
run;
Schilker
  • 505
  • 2
  • 11
  • Hi Schilker, I will give this try and will keep in mind about the sample data and expected output next time. Still learning SO..Thank you! – user168836 Jan 02 '20 at 21:04