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

I have a data that I'm trying to adjust based on the row number, or say row name, 

say I have the data below

 

data mydata;
input indix $ prod1-prod6;
cards;
ind1 0.4 5 2 3 11 13
ind2 1 7 10 20 15 25
ind3 4 2 6 10 13 24
ind4 5 6 15 27 31 22
ind5 18 1 28 38 11 12
ind6 18 1 22 39 13 12
ind7 10 2 19 40 10 11
ind8 11 9 40 70 2 10
;
run;

Abdulla1_0-1649261367588.png

 

I want to drop the prod# if it has ind5 and ind6 identical. (which will drop prod1 prod2 and Prod6)

moreover, I have a dataset that has more than 100 line. is there a quick way to keep only the first 6 rows and delete the rest.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Abdulla1
Quartz | Level 8

@Abdulla1 wrote:

I want to drop the prod# if it has ind5 and ind6 identical. (which will drop prod1 prod2 and Prod6)


I figured out the following way of doing it.

data mydata;
input indix $ prod1-prod6;
cards;
ind1 0.4 5 2 3 11 13
ind2 1 7 10 20 15 25
ind3 4 2 6 10 13 24
ind4 5 6 15 27 31 22
ind5 18 1 28 38 11 12
ind6 18 1 22 39 13 12
ind7 10 2 19 40 10 11
ind8 11 9 40 70 2 10
;
run;

proc transpose data=mydata(RENAME=(indix=_NAME_)) out=TEMPDATA1;run;
data TEMPDATA2;
set TEMPDATA1;
if ind5=ind6 THEN DELETE;
RUN;
proc transpose data=TEMPDATA2 out=WANT(rename=(_NAME_=indix));run;

View solution in original post

4 REPLIES 4
Abdulla1
Quartz | Level 8
I'm not sure why the code appeared in this way. please find the data code below:
data mydata;
input indix $ prod1-prod6;
cards;
ind1 0.4 5 2 3 11 13
ind2 1 7 10 20 15 25
ind3 4 2 6 10 13 24
ind4 5 6 15 27 31 22
ind5 18 1 28 38 11 12
ind6 18 1 22 39 13 12
ind7 10 2 19 40 10 11
ind8 11 9 40 70 2 10
;
run;
ballardw
Super User

I have a dataset that has more than 100 line. is there a quick way to keep only the first 6 rows and delete the rest.

 


 

Data want;
   set have (obs=6);
run;

creates a new data set Want with the first 6 observations from Have.

The data set option OBS can be used anywhere you are specifying the set to use. So

Proc print data=have (obs=6);
run;

only prints the first 6 observations without removing any. This will work for input into any procedure.

 

There is also a FIRSTOBS= data set option ;

Data want; 
   set have (firstobs=7);
run;

which would create a new data set starting with the 7th observation in Have.

 

Abdulla1
Quartz | Level 8
Thank you ballardw
That was very helpful.
Abdulla1
Quartz | Level 8

@Abdulla1 wrote:

I want to drop the prod# if it has ind5 and ind6 identical. (which will drop prod1 prod2 and Prod6)


I figured out the following way of doing it.

data mydata;
input indix $ prod1-prod6;
cards;
ind1 0.4 5 2 3 11 13
ind2 1 7 10 20 15 25
ind3 4 2 6 10 13 24
ind4 5 6 15 27 31 22
ind5 18 1 28 38 11 12
ind6 18 1 22 39 13 12
ind7 10 2 19 40 10 11
ind8 11 9 40 70 2 10
;
run;

proc transpose data=mydata(RENAME=(indix=_NAME_)) out=TEMPDATA1;run;
data TEMPDATA2;
set TEMPDATA1;
if ind5=ind6 THEN DELETE;
RUN;
proc transpose data=TEMPDATA2 out=WANT(rename=(_NAME_=indix));run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1343 views
  • 3 likes
  • 2 in conversation