This is the data I have and want.
data want; input ID visit question response v1_response; cards; 1 1 1 4 4 1 2 1 3 4 1 1 2 6 6 1 2 2 9 6 ;
Basically, I want to create variable v1_response, where it shows the visit 1 response by ID and question in order to calculate the change from visit 1 score for each question. I know how to do this when it is only 1 question in the dataset. But my approach is keeping only the value of the first question across all questions.
This is my code so far
data have; input ID visit question response; cards; 1 1 1 4 1 2 1 3 1 1 2 6 1 2 2 9 ; proc sort data=have; by ID visit question; run; data want; set have; by ID visit question; retain v1_response; if first.ID AND first.question and visit=1 then do; v1_response=response; end; else if visit GT 1 do; change=response-v1_response; end; run;
Because of the by statement, SAS keeps track of the by variables, and sets the first. and last. variables at every group change.
Keep the order as is, run the data step with
by id question;
and set v1_response at first.question.
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.
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.