LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 23 Aug 2007 14:49:13 -0400
Reply-To:     Jack Clark <JClark@CHPDM.UMBC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Clark <JClark@CHPDM.UMBC.EDU>
Subject:      Re: Access a specific observation?
Comments: To: Brandon_Thinkpad <brandonpen@GMAIL.COM>
In-Reply-To:  A<1187891917.680845.73330@i38g2000prf.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"

Hello,

You could consider building a format from the values of ACROMERGED in data set #2, then applying that format to the CC and UID variables in data set #1.

* create sample data for data set #1 ; data ds1; input cc $ uid $ ; cards; AAA BBB AAA XXX ZZZ ZZZ UUU CCC DDD DDD OOO OOO BBB YYY GGG AAA ; run;

* create sample data for data set #2 ; data ds2; input acromerged $ ; cards; AAA BBB CCC DDD ; run;

* build format from data set # 2 ; data mkfmt; set ds2 (keep=acromerged) end=eof; fmtname = 'acro'; start = acromerged; type = 'C'; label = 'XTRUE'; output; if eof then do; hlo = 'O'; label = 'FALSE'; output; end; run;

proc format library = work cntlin = mkfmt; run;

* apply format to CC and UID variables ; data need; set ds1; stringfoundcc = put(cc,$acro.); stringfounduid = put(uid,$acro.); run;

proc print data = need; run;

Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Brandon_Thinkpad Sent: Thursday, August 23, 2007 1:59 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Access a specific observation?

This reply was very helpful!

My task is to compare observations in two columns of a dataset, against the value of a variable. More specifically, it is to search for columns CC and UID against a variable string AcroMerged.

if find (AcroMerged, CC, 't') then StringFoundCC='XTRUE'; if find (AcroMerged, UID, 't') then StringFoundUID='XTRUE'; if not find(AcroMerged, UID, 't') then StringFoundCC='FALSE'; if not find (AcroMerged, UID, 't') then StringFoundUID='FALSE';

The problem is that I want to compare every value of CC and UID (from the first dataset) against the FIRST LINE of AcroMerged (in a second dataset), and then the SECOND LINE of AcroMerged, and then the THIRD line of AcroMerged, and then the FOURTH LINE of AcroMerged, etc. until the end of the second dataset. I had some code that semi-works, however it seems like it compares each instance of the observations against the corresponding observation in the second data set. Whereas the first dataset could potentially be hundreds of thousands of lines long, the second data set is only a few hundred lines long. It stopped searching at the end of the second data set.

I figured I could do the comparisons using an array technique and a counter.

On Aug 23, 12:41 pm, nos...@HOWLES.COM ("Howard Schreier <hs AT dc-sug DOT org>") wrote: > On Thu, 23 Aug 2007 15:54:30 +0000, toby dunn <tobyd...@HOTMAIL.COM> wrote: > >Data Test ; > >Infile Cards ; > >Input Text $ ; > >If _N_ In ( 1 3 ) ; > >Cards ; > >Hello > >Goodbye > >NoDeal > >; > >Run ; > > >Proc Print > >Data = Test ; > >Run ; > > >Toby Dunn > > >From: Brandon_Thinkpad <brandon...@GMAIL.COM> > >Reply-To: Brandon_Thinkpad <brandon...@GMAIL.COM> > >To: SA...@LISTSERV.UGA.EDU > >Subject: Access a specific observation? > >Date: Thu, 23 Aug 2007 08:49:10 -0700 > > >I am relatively new to the world of SAS, and I would like to know > >specifically how to read a specific observation --- I was hoping that

> >this worked similarly to reading a specific array index, but it > >doesn't appear to be the case. > > >For example, I submit the following pseudo-code : > >------------------------------- > >data TESTINGARRAYS; > >file = 'c:\specific-observation-output.txt'; > > >input testing; > > >put testing(OBSEVATION # 1); > >put testing (OBSERVATION # 3); > > >datalines; > >Hello > >Goodbye > >NoDeal > >; > >------------------------------ > > >I am having trouble working with specific observation numbers in > >general; any assistance would be appreciated! BTW, the desired > >output for the above program would be to output "Hello" and "NoDeal" > >to the file specific-observation-output.txt, while omitting the > >second observation "Goodbye". > > You can do this once your data reside in a SAS data set. Adapting > Toby's > example: > > Data Test ; > Infile Cards ; > Input Text $ ; > Cards ; > Hello > Goodbye > NoDeal > ; > > data _null_; > do wanted_obs = 1, 3; > set test point=wanted_obs; > put text; > end; > stop; > run; > > However, this is not a mainstream way of doing things in SAS. Perhaps > if we know the actual task we can make other suggestions.


Back to: Top of message | Previous page | Main SAS-L page