LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 28 Apr 2005 16:02:53 -0500
Reply-To:   matt.pettis@THOMSON.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Matt Pettis <matt.pettis@THOMSON.COM>
Subject:   Re: Filename PIPE and Datastep DOW loop
Comments:   To: jfh@stanfordalumni.org
Content-Type:   text/plain; charset="us-ascii"

Hi,

A big thank-you to Jack Hamilton and everybody else who contributed. I was able to fit Jack's second solution to my needs quite easily and with minor changes. I'm including the log with the code for posterity on the list...

BTW, I asked SAS Technical support this very question two years ago and they couldn't answer it (I ended up writing out a temp file and writing a perl job to lookup everything in the file, append the looked up name, and then reading the file back into SAS. Not pretty.).

Thanks again for everybody's help. Using SAS-L has made me look like a genius at work... however, my wife still thinks I'm a dork -- SAS-L or no SAS-L.

Sincerely, Matt Pettis ----------- 467 DATA IP; 468 INFILE DATALINES; 469 INPUT IP:$15.; 470 DATALINES;

NOTE: The data set WORK.IP has 2 observations and 1 variables. NOTE: Compressing data set WORK.IP increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.00 seconds

473 ; 474 DATA IP; 475 SET IP; 476 LENGTH COMMAND $24; 477 COMMAND = 'NSLOOKUP '||IP; 478 EOP = 0; 479 INFILE NSLOOKUP PIPE FILEVAR=COMMAND END=EOP; 480 LENGTH NAME $ 64; 481 DO UNTIL (EOP); 482 INPUT; PUT _INFILE_; 483 IF _INFILE_ =: 'Name' THEN NAME = TRIM(LEFT(SCAN(_INFILE_,2,':'))); 484 END; 485 RUN;

NOTE: The infile NSLOOKUP is: Unnamed Pipe Access Device, PROCESS=NSLOOKUP 207.255.105.92,RECFM=V, LRECL=256

Server: eg-ecomdc-a05.ecom.tlrg.com Address: 167.68.80.161

Name: 207-255-105-092-dhcp.unt.pa.atlanticbb.net Address: 207.255.105.92 NOTE: The infile NSLOOKUP is: Unnamed Pipe Access Device, PROCESS=NSLOOKUP 207.255.105.193,RECFM=V, LRECL=256

Server: eg-ecomdc-a05.ecom.tlrg.com Address: 167.68.80.161

Name: 207-255-105-193-dhcp.unt.pa.atlanticbb.net Address: 207.255.105.193 NOTE: 6 records were read from the infile NSLOOKUP. The minimum record length was 0. The maximum record length was 51. NOTE: 6 records were read from the infile NSLOOKUP. The minimum record length was 0. The maximum record length was 51. NOTE: There were 2 observations read from the data set WORK.IP. NOTE: The data set WORK.IP has 2 observations and 2 variables. NOTE: Compressing data set WORK.IP increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.21 seconds cpu time 0.03 seconds

486 DATA _NULL_; 487 SET IP; 488 PUT IP= NAME=; 489 RUN;

IP=207.255.105.92 NAME=207-255-105-092-dhcp.unt.pa.atlanticbb.net IP=207.255.105.193 NAME=207-255-105-193-dhcp.unt.pa.atlanticbb.net NOTE: There were 2 observations read from the data set WORK.IP. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

-----Original Message----- From: Jack Hamilton [mailto:jfh@stanfordalumni.org] Sent: Thursday, April 28, 2005 3:01 PM To: SAS-L@LISTSERV.UGA.EDU; Pettis, Matthew (TLR Corp) Subject: RE: [SAS-L] Filename PIPE and Datastep DOW loop

Also, the loop you coded is not a DOW loop, it's just an ordinary loop.

It's possible to do the equivalent of changing a filename statement with the pipe engine inside a data step (see example 3 at <http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000210819.ht m#a0 00842980>), but why do you need to do that? Why not just use two 00842980>different filename statements? Is your actual problem more complicated than the one shown?

Here's more code for you to look at:

===== data _null_; command = 'nslookup 207.255.105.92'; infile ns1 pipe filevar=command end=eod1; do until (eod1); input; put '(1) ' _infile_; end; command = 'nslookup 207.255.105.93'; infile ns2 pipe filevar=command end=eod2; do until (eod2); input; put '(2) ' _infile_; end; stop; run;

data _null_; do command = 'nslookup 207.255.105.92', 'nslookup 207.255.105.93'; eod = 0; infile nslookup pipe filevar=command end=eod; do until (eod); input; put command ':' _infile_; end; end; stop; run; =====

and here is the log:

===== 332 data _null_; 333 command = 'nslookup 207.255.105.92'; 334 infile ns1 pipe filevar=command end=eod1; 335 do until (eod1); 336 input; 337 put '(1) ' _infile_; 338 end; 339 command = 'nslookup 207.255.105.93'; 340 infile ns2 pipe filevar=command end=eod2; 341 do until (eod2); 342 input; 343 put '(2) ' _infile_; 344 end; 345 stop; 346 run;

NOTE: The infile NS1 is: Unnamed Pipe Access Device, PROCESS=nslookup 207.255.105.92,RECFM=V, LRECL=256

(1) Server: spoke.dcn.davis.ca.us (1) Address: 168.150.253.2 (1) (1) Name: 207-255-105-092-dhcp.unt.pa.atlanticbb.net (1) Address: 207.255.105.92 (1) NOTE: The infile NS2 is: Unnamed Pipe Access Device, PROCESS=nslookup 207.255.105.93,RECFM=V, LRECL=256

(2) Server: spoke.dcn.davis.ca.us (2) Address: 168.150.253.2 (2) (2) Name: 207-255-105-093-dhcp.unt.pa.atlanticbb.net (2) Address: 207.255.105.93 (2) NOTE: 6 records were read from the infile NS1. The minimum record length was 0. The maximum record length was 51. NOTE: 6 records were read from the infile NS2. The minimum record length was 0. The maximum record length was 51. NOTE: DATA statement used (Total process time): real time 0.75 seconds cpu time 0.01 seconds

347 348 data _null_; 349 do command = 'nslookup 207.255.105.92', 'nslookup 207.255.105.93'; 350 eod = 0; 351 infile nslookup pipe filevar=command end=eod; 352 do until (eod); 353 input; 354 put command ':' _infile_; 355 end; 356 end; 357 stop; 358 run;

NOTE: The infile NSLOOKUP is: Unnamed Pipe Access Device, PROCESS=nslookup 207.255.105.92,RECFM=V, LRECL=256

nslookup 207.255.105.92 :Server: spoke.dcn.davis.ca.us nslookup 207.255.105.92 :Address: 168.150.253.2 nslookup 207.255.105.92 : nslookup 207.255.105.92 :Name: 207-255-105-092-dhcp.unt.pa.atlanticbb.net nslookup 207.255.105.92 :Address: 207.255.105.92 nslookup 207.255.105.92 : NOTE: The infile NSLOOKUP is: Unnamed Pipe Access Device, PROCESS=nslookup 207.255.105.93,RECFM=V, LRECL=256

nslookup 207.255.105.93 :Server: spoke.dcn.davis.ca.us nslookup 207.255.105.93 :Address: 168.150.253.2 nslookup 207.255.105.93 : nslookup 207.255.105.93 :Name: 207-255-105-093-dhcp.unt.pa.atlanticbb.net nslookup 207.255.105.93 :Address: 207.255.105.93 nslookup 207.255.105.93 : NOTE: 6 records were read from the infile NSLOOKUP. The minimum record length was 0. The maximum record length was 51. NOTE: 6 records were read from the infile NSLOOKUP. The minimum record length was 0. The maximum record length was 51. NOTE: DATA statement used (Total process time): real time 0.75 seconds cpu time 0.03 seconds =====

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Jack Hamilton > Sent: Thursday, April 28, 2005 12:37 pm > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: [SAS-L] Filename PIPE and Datastep DOW loop > > FILENAME is a global statement, not a data step statement. > The FILENAME > statements are executed before any of the data step statements. Since

> you're reusing the filename NSLKUP, only the second definition is in > effect when the data step executes. > > Suggestions: > > 1) Use two different filename statements, one for each different OS > command you want to execute. > > 2) As a matter of style, move FILENAME (and LIBNAME) statements before

> the DATA statement; this will make it more clear that they're not > executed at runtime. > > Run this program: > > ===== > DATA _NULL_; > FILENAME NSLKUP PIPE 'NSLOOKUP 207.255.105.92'; > INFILE NSLKUP END=EOF; > put 'before first loop'; > DO UNTIL (EOF); > INPUT; > PUT '(1) ' _INFILE_; > END; > put 'before second loop'; > FILENAME NSLKUP CLEAR; > FILENAME NSLKUP PIPE 'NSLOOKUP 207.255.105.93'; > INFILE NSLKUP END=EOF; > DO UNTIL (EOF); > INPUT; > PUT '(2) ' _INFILE_; > END; > put 'after second loop'; > RUN; > ===== > > And you'll see that it's only the first loop that's being executed. > > > > > > > -----Original Message----- > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of

> > Matt Pettis > > Sent: Thursday, April 28, 2005 11:56 am > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: [SAS-L] Filename PIPE and Datastep DOW loop > > > > Hi, > > > > I would like to make a datastep execute an external command with an > > unnamed pipe which changes arguments based on data read into the > > datastep and then parse the STDOUT. My first attempts have not been

> > fruitful, as only the pipe with the last assigned value gives me > > output. Can I change the filename pipe in a loop in the datastep > > and parse the output of the pipe in a DOW loop? If not, why not, > > and is there a workaround? > > > > I think that my problem can be illustrated in the following log with

> > the attendant question: why is only the output from the second > > command output, and not the first? > > > > TIA, > > Matt > > ------ > > 239 DATA _NULL_; > > 240 FILENAME NSLKUP PIPE 'NSLOOKUP 207.255.105.92'; > > 241 INFILE NSLKUP END=EOF; > > 242 DO UNTIL (EOF); > > 243 INPUT; > > 244 PUT _INFILE_; > > 245 END; > > 246 FILENAME NSLKUP CLEAR; > > NOTE: Fileref NSLKUP has been deassigned. > > 247 FILENAME NSLKUP PIPE 'NSLOOKUP 207.255.105.93'; > > 248 INFILE NSLKUP END=EOF; > > 249 DO UNTIL (EOF); > > 250 INPUT; > > 251 PUT _INFILE_; > > 252 END; > > 253 RUN; > > > > NOTE: The infile NSLKUP is: > > Unnamed Pipe Access Device, > > PROCESS=NSLOOKUP 207.255.105.93,RECFM=V, > > LRECL=256 > > > > Server: eg-ecomdc-a05.ecom.tlrg.com > > Address: 167.68.80.161 > > > > Name: 207-255-105-093-dhcp.unt.pa.atlanticbb.net > > Address: 207.255.105.93 > > NOTE: 6 records were read from the infile NSLKUP. > > The minimum record length was 0. > > The maximum record length was 51. > > NOTE: DATA statement used (Total process time): > > real time 0.07 seconds > > cpu time 0.00 seconds > > >


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