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;
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.
@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;
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 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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: