BookmarkSubscribeRSS Feed
blmreil
Calcite | Level 5

Hi. I'm new to SAS so I'd greatly appreciate any help anyone could provide me. So say, I have a data set with ~500 observations and my ultimate goal is to run ANCOVA of this data set with response variable y, factors i and j, and possible covariates k and l. I have 5 levels of i and two levels of j. Since, I first want to try to run a completely balanced ANCOVA, I don't want to use the entire data set, just the first n observations (according to ID) for each of the ten factor-level combinations.

 

I initially wrote a line with

 

IF (ID > 10*n) then delete;

before realizing how stupid that is.

 

How would I go about doing this?

 

Here's a mockup of what part of the data looks like:

 

ID   i    j   k   l   y
1    3   1
2    3   1
3    2   1
4    4   1
5    5   2
6    1   1
7    4   2
8    2   2
9    3   1
10   5   2
11  1   1
12   3   2
13   2   1
14   1  2
15   5  1
...

 

So i=1, j=1, would have ID 11 as the first observation.
and i=2, j=1, would have ID 3, ID 13, etc.

 

It feels like this should be a pretty simple thing to do but I cannot for the life of me figure out how to do it. Would anybody be able to point me in the right direction? Thanks in advance for your help!

4 REPLIES 4
KachiM
Rhodochrosite | Level 12

Hi,

There are many ways to get the first N obsevations.

Use the statement as:

 

IF (ID > n) then delete;

 If your data set is named as MYDATA, then use;

set MYDATA(obs=n);

blmreil
Calcite | Level 5

Hi,

 

Thanks for your reply.  And sorry for not explaining it more clearly. I want to make it so each i-j combination has the same number of observations. If I do ID>200 or MYDATA(obs=200), it looks like it will just pull whatever the first 200 observations are. I want each combination to have 20 observations. 

 

proc freq.png

KachiM
Rhodochrosite | Level 12

Yes. Now I see your requirement. It takes more time to give you solution without knowing some sample data set. Again you may want random sample in each i-j th combination. I have very limited time to give you a solution immediately. Someone will help you soon.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 704 views
  • 0 likes
  • 2 in conversation