DATA Step, Macro, Functions and more

coding date to sequence and regression coefficients output

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

coding date to sequence and regression coefficients output

I have ID, amount, date in my data sets, and each ID has a number of amount & date.

Now I want to have a sequence variable, that for each ID, the first date has sequence value 1, the second date has sequence value 2, etc. For those with has only 1 date, delete.

 

can anyone tell me how to do this? I sort by ID and date, and use first.ID and last.ID to loop?

 

another question is, after I have the sequence variable, I want to use regression (DV=amount, IV=sequence) to see the trend of the amount, positive or negative. I want to have a new data set with only ID and Beta (coefficients).

PROC REG DATA=with_sequence;
   BY ID ;
   MODEL amount= sequence ;
   output out=b;
RUN; 

Is this the right way to do  it?


Accepted Solutions
Solution
‎03-09-2016 03:53 PM
Super User
Posts: 17,910

Re: coding date to sequence and regression coefficients output


All Replies
Solution
‎03-09-2016 03:53 PM
Super User
Posts: 17,910

Re: coding date to sequence and regression coefficients output

Is this what you're trying to do:

 

http://www.ats.ucla.edu/stat/sas/faq/enumerate.htm

 

Super Contributor
Posts: 312

Re: coding date to sequence and regression coefficients output

Thank you! The first problem solved. I can use this example:

data two;
  input class gender score;
  cards;
  1 1 48
  1 1 45
  2 2 50
  1 2 42
  2 1 41
  2 2 51
  2 1 52
  1 1 43
  1 2 52
  ;
run;

proc sort data = two;
  by class gender;
run;

data two1;
  set two;
  count + 1;
  by class gender;
  if first.gender then count = 1;
run;

proc print data = two1;
run;
Super User
Posts: 17,910

Re: coding date to sequence and regression coefficients output

For your second question look at the output tables, but you may also be interested in teh ODS output tables. I think the one you're after is called ParameterEstimates.

 

ods table parameterEstimates=want;
Proc reg......;
*rest of code;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 235 views
  • 0 likes
  • 2 in conversation