BookmarkSubscribeRSS Feed
Nav_Sweeney
Calcite | Level 5

I have a dataset with 3 columns:

1. Student id

2. date

3. Marks

In the date column, I have values in mmddyy10 from jan11-dec12. The Marks column contains values of marks for each day for the period jan11-dec12.

I want to calculate a new variable called percentagedifference_30days that should have corresponding values from jan 31st.

Formula: percentagedifference_30days= (jan31st mark - jan1st mark/jan 1st mark)

So start from Jan 31st, I want Percentagedifference_30days calculated for each day and for each student_id. The result value shoud roll for the whole year.

The idea of this excercise is to determine the growth or decrease of each student for the whole year. So can anybody provide me the base SAS code plz?

2 REPLIES 2
Cynthia_sas
SAS Super FREQ


Hi:

  It would be most useful to other folks who might be inclined to help you if you provided:

1) a copy of your code or the code you've tried

2) some data to try -- for example when you have "marks" as the 3rd variable, I thought it might be 1 number, but then you said "contains values of marks for each day" So I can't envision your data because it is not clear whether you have this:

Alan 01/01/2011 98   <--- one mark

or

Alan 01/01/2011 98 95 98  <--- multiple marks for the same day

3) some idea of what this is needed for (you need a report showing the percent difference, you need an output data set that contains the new variable)

4) an idea of further processing or handing. For example -- if you need an output dataset -- what other analysis do you need to perform? if you need a report -- what type of report -- HTML, RTF, PDF?

cynthia

Haikuo
Onyx | Level 15

Well, if I understand you correctly, you are trying to mark improvement percent base on 30 days interval. Here is one approach you could meddle around to suit your need:

data have;

  do id=1 to 10;

     do date=1 to 365;

          mark=ceil(ranuni(0)*100);

            output;

       end;

  end;

run;

data want;

   array t(0:30) _temporary_;

do _n_=1 by 1 until (last.id);

set have;

   by id;

   t(mod(_n_,31))=mark;

   if _n_>=31 then pct=(t(mod(_n_,31))-t(mod((_n_-30),31)))/t(mod((_n_-30),31));

   output;

end;

run;

Haikuo


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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