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

I need to create a new data set using the Have dataset. The conditons are as follow:

1. Include all observations with Column C = C

2. Select random observations with Column C = T where sum of  TTL_PLST less than or equal to 20. ** Note: The records highlighted in Red make a sum of 20 where Column C = T.**

Dataset Have

Column AColumn BColumn CColumn DTTL_PLSTN
1234567891ACNP11
1234567891ACNP233
1234567891ACNP321
1234567891ACNP42
1234567891ACNP564
1234567891ACNP62
1234567891ACNP797
1234567891ATNP810
1234567891ATNP91
1234567891ATNP103
1234567891ATNP111
1234567891ATNP31
1234567891ATNP132
1234567891ATNP14264
1234567891ATNP151

Want Dataset:

Column AColumn BColumn CColumn DTTL_PLSTN
1234567891ACNP11
1234567891ACNP233
1234567891ACNP321
1234567891ACNP42
1234567891ACNP564
1234567891ACNP62
1234567891ACNP797
1234567891ATNP              8  10
1234567891ATNP              9   1
1234567891ATNP              3   1
1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

how about:

data have ;

input Column_A $9. Column_B $ Column_C $ Column_D $ TTL_PLST N ;

cards;

123456789 1A C  NP 1 1

123456789 1A C  NP 2 33

123456789 1A C  NP 3 21

123456789 1A C  NP 4 2

123456789 1A C  NP 5 64

123456789 1A C  NP 6 2

123456789 1A C  NP 7 97

123456789 1A T  NP 8 10

123456789 1A T  NP 9 1

123456789 1A T  NP 10 3

123456789 1A T  NP 11 1

123456789 1A T  NP 3 1

123456789 1A T  NP 13 2

123456789 1A T  NP 14 264

123456789 1A T  NP 15 1

;

proc sort data=have out=have1(where=(column_c='T'));

  by TTL_PLST;

run;

data have1(drop=total);

  set have1;

  retain total;

   total+TTL_PLST;

  if total <=20;

run;

data want;

   set have (where=(column_c='C'))

     have1;

run;

Linlin

View solution in original post

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

how about:

data have ;

input Column_A $9. Column_B $ Column_C $ Column_D $ TTL_PLST N ;

cards;

123456789 1A C  NP 1 1

123456789 1A C  NP 2 33

123456789 1A C  NP 3 21

123456789 1A C  NP 4 2

123456789 1A C  NP 5 64

123456789 1A C  NP 6 2

123456789 1A C  NP 7 97

123456789 1A T  NP 8 10

123456789 1A T  NP 9 1

123456789 1A T  NP 10 3

123456789 1A T  NP 11 1

123456789 1A T  NP 3 1

123456789 1A T  NP 13 2

123456789 1A T  NP 14 264

123456789 1A T  NP 15 1

;

proc sort data=have out=have1(where=(column_c='T'));

  by TTL_PLST;

run;

data have1(drop=total);

  set have1;

  retain total;

   total+TTL_PLST;

  if total <=20;

run;

data want;

   set have (where=(column_c='C'))

     have1;

run;

Linlin

Hima
Obsidian | Level 7

Thanks for your quick reply Linlin. Looking at the original data, I totally lost what I was doing. So, I had to post it here.

Ksharp
Super User

Can't understand what you mean about 'Randomly Select observation'

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!

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.

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
  • 3 replies
  • 704 views
  • 0 likes
  • 3 in conversation