BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hello all... I have value as follow

type | seq | id

900 | 1 | 12345
905 | 2 | 12345
166 | 3 | 12345
900 | 1 | 90171
905 | 2 | 90171
900 | 1 | 11145
905 | 2 | 11145
105 | 3 | 11145

what is my syntax should I want to output id for the asm_type only in 900, and 905 so in this case, the syntax would output 90171 only and count it as 1.

any help on this is greatly appreciated

thanks
regards...
neobita
7 REPLIES 7
LinusH
Tourmaline | Level 20
I'm not exactly clear how you want your output (best is to show an example output table as well).
Maybe PROC SORT NODUPKEY/PROC SQL Select Distinct with a WHERE-clause will do your job...?

/Linus
Data never sleeps
deleted_user
Not applicable
thank you for seeing my topic...

my output would be in a html format report... all i want is a select statement that can output a condition of asm_type = '900' and asm_type = '905' and not anything else.... even-though an id contains the '900' and '905' as its first two asm type, and if it has a third asm type, I would neglect the id all together... I am very new at sas, I hope my explanation is good enuf...

regards
Flip
Fluorite | Level 6
data one;
input type seq id;
cards;
900 1 12345
905 2 12345
166 3 12345
900 1 90171
905 2 90171
900 1 11145
905 2 11145
105 3 11145
run;

proc sql;
create table two as select distinct id, type from one where id not in (select id from one where
seq GE 3);
quit;
deleted_user
Not applicable
it seems that I'm still unable to get the result I wanted. I want to output the ID with ASSET 900 for SEQ 1 and ID with ASSET 905 for SEQ 2 as a single ID and without a third SEQ

inside the database, it shows the following data.

ID----------------YEAR-----------TYP----------ASSET--------SEQ
76039803------2006--------------1---------------900-------------1
76039803------2006--------------1---------------905-------------2
77318706------2006--------------1---------------900-------------1
77318706------2006--------------1---------------905-------------2
86856104------2006--------------1---------------900-------------1
86856104------2006--------------1---------------905-------------2
88458302------2006--------------1---------------900-------------1
88458302------2006--------------1---------------905-------------2
200180480-----2006--------------1---------------900-------------1
200180480-----2006--------------1---------------905-------------2
276493707-----2006--------------1---------------900-------------1
276493707-----2006--------------1---------------905-------------2
687509501-----2006--------------1---------------105-------------3
687509501-----2006--------------1---------------900-------------1
687509501-----2006--------------1---------------905-------------2
123123123-----2006--------------1---------------900-------------0
123123123-----2006--------------1---------------905-------------1
88888888------2006--------------1---------------900-------------1
88888888------2006--------------1---------------123-------------2
99999999------2006--------------1---------------111-------------1
99999999------2006--------------1---------------905-------------2


The id that I want would be 076039803, 077318706 , 086856104 , 088458302 , 2001804807 and 276493707.

I Don't want the following ID
687509501 - because it contains more than 2 seq
123123123 - because it starts with seq 0
88888888 - because the second sequence ASSET is 123
99999999 - because the first sequence ASSET is 111

kindly share some light to this humble programmer.... any help given is truly appreciated,

regards
neobita
DanielSantos
Barite | Level 11
Hi.

Try this:
[pre]
* ensure data is sorted;
proc sort data=INDATA;
by ID;
run;

data OUTDATA;
set INDATA;
by ID;
retain _GOOD; * flag;
keep ID;
if first.ID then _GOOD=1; * assume its a good ID;
if SEQ not in (1,2) or ASSET not in (900,905) then _GOOD=0; * fails;
if last.ID and _GOOD; * output last obs if good ID;
run;
[/pre]

Works with your sample, but please do some more intensive tests.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Peter_C
Rhodochrosite | Level 12
[pre]data two ;
do row=1 by 1 until( last.id ) ;
set origs ;
by id notsorted ;
if asset = '900' and seq=1 then f1='1' ;
if asset = '905' and seq=2 then f2='1' ;
else f3= '1' ;
end ;
if f3 ne '1' and f1!!f2 = '11' then output ;
run;[/pre]
abdullala
Calcite | Level 5
data one;
input type seq id;
cards;
900 1 12345
905 2 12345
166 3 12345
900 1 90171
905 2 90171
900 1 11145
905 2 11145
105 3 11145
run;


proc sql;
create table justtwo as
select distinct id from one
group by id
having count(id) =2 ;
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 1049 views
  • 0 likes
  • 6 in conversation