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

Hello, 

   I have the following data set.

city     Year     D87      X     dx

  1        82      0           a       -

  2        87      1          b       (b-a)

  3        82      0          c       -

  4        87      1          d      (d-c)

  5        82      0          e       -

  6        87      1          f       (f-e)

What procedure should be used to achieve dx ?

Thank You

1 ACCEPTED SOLUTION

Accepted Solutions
Golf
Quartz | Level 8
Thank you for your suggestion.
Best,

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

In a data step:

 

pX = lag(X);
if D87 then dx = X - pX;
drop pX;

PG
Golf
Quartz | Level 8
Thank You.
Golf
Quartz | Level 8

L_x = lag(x);
dx = x-L_x;
if d87 = 0 then dx = .;

mkeintz
Jade | Level 19

Or you could use the DIF function, defined as X-lag(X):

 

   dx=dif(x);

   if d87=0 then dx=.;

 

Or slightly more economical. 

 

    dx= ifn(d87=1,dif(x),.) ;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Golf
Quartz | Level 8
Thank you for your suggestion.
Best,
FreelanceReinh
Jade | Level 19

Hello @Golf,

Glad to see that mkeintz's solution worked for you. Then it would be fair and help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select his post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
show_option_menu.png

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 615 views
  • 4 likes
  • 5 in conversation