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 (December 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 4 Dec 2003 12:17:42 -0500
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: Debugging SAS with many variables (newbie)
Comments: To: Carl Kyonka <Carl.Kyonka@ENBRIDGE.COM>
Content-Type: text/plain

Carl,

The ideal solution is to use the file layout specification as control data to generate the INPUT statement. Then it will be as correct as the specification is. If you can post a sample of what the layout looks like and in what form it is electronically stored, someone can probably give you very good advice.

The DUMP is produced by the LIST command and PUT _ALL_. These commands are triggered by having the automatic variable _ERROR_ set to 1. The order of variables in the dump and on the SAS dataset is controlled by their order of appearance in the creating DATA step. Usually this means the dump will be in the order of the variables in the INPUT statement. Since it is not true for you there must be other statements preceding the INPUT statement. One of your requests could be satisfied by ordering the variables correctly in those statements.

However there may be a simpler solution. Let's suppose you have

input x 3. a $char5. z 8. ;

You could copy that statement in a text editor and remove everything but the variable names. In the example the result is

x a z

You could then add RETAIN at the beginning and a semicolon at the end.

retain x a z ;

This statement could then be made the first line of the DATA step. It will force the order of variables in the dump without prejudicing the variable type. However, it has a side affect that the variables named will not automatically be set to missing. This may or may not cause problems with the logic of your DATA step so it would probably be good to remove this line, once you have finished debugging.

Here is an example illustrating a way to easily obtain an alphabetic order.

data w ; /* copy of your input data step */ infile cards obs = 1 ; /* modified INFILE */ input x y a ; cards ; 1 2 3 4 5 6 7 8 9 ;

proc contents data = w out=c(keep = name) noprint ; run ;

proc sql noprint ; select name into :varlist separated by " " from c ; quit ;

data w ; /* your real input data step for debugging */ retain &varlist ; /* inserted RETAIN statement */ input x y a ; cards ; 1 2 3 ;

The SQL step creates what is called a macro variable. In this case VARLIST. It holds the whole column of variable names. (In version 8.2 it can be up to 64K long, so you probably will have plenty of room unless you INPUT statement is more than 100+ pages long.) The & in the RETAIN statement is a reference to this macro variable. If you want to see the value add

options symbolgen ;

in front of the input DATA step, or use

%put &varlist ;

I have illustrated with CARDS so that anyone could execute the code. Your input DATA step will be much longer and more complex but it shouldn't make any difference, the principle is the same.

IanWhitlock@westat.com

-----Original Message----- From: Carl Kyonka [mailto:Carl.Kyonka@ENBRIDGE.COM] Sent: Thursday, December 04, 2003 10:39 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Debugging SAS with many variables (newbie)

I have a file with mixed numeric and alphabetic variables. I am slogging my way through writing an INPUT statement to read these records. I get errors with a somewhat helpful dump of the input record and the variables as they stand when an error occurred. My difficulty is that there are lots of variables and finding the ones I want is awkward. I can use the find command to locate each variable in the sequence they are listed in the INPUT statement, but that is time-consuming. This may be well documented, but I do not know what to call this record dump so I have not found it in on-line doc. What I would like is an option to sort the variables being dumped either alphabetically or in the INPUT sequence. Or a tactic to help debugging the INPUT statement. Thanks for the time, Carl Kyonka


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