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 (December 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 19 Dec 2000 15:06:11 -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: Question on usage of data conversion functions in a Data Step
              ;
Comments: To: Vivek Annamalai <annamalaiv@HOTMAIL.COM>
Content-Type: text/plain; charset="iso-8859-1"

Vivek,

The line

if data_mon = . then data_mon = input(put(dm,6.),yymmn6.);

contains a subtle error. Consider the first value of DATA_MON in TEST2. It is missing. Thus the value is replaced according to the above. Now it is not missing. Since it comes from a SAS data set it is not reset to missing. Since it is not on TEST2 the value cannot be clobbered by reading a new record. Hence it will not change on any subsequent records.

Your work around

if dm ^= . then data_mon = input(put(dm,6.),yymmn6.);

corrects the problem. However, I think most good SAS programmers would prefer to test with an IN= variable, since it makes clear the intent - for TEST2 get the value of DATA_MON from DM. With your code one has to think - ah DM is on TEST2; thus it shouldn't be missing when reading TEST2; DATA_MON is not on TEST2; oh, so he wants to populate DATA_MON on TEST2 with values from DM.

Good coding consists of more than getting it right. It also means getting the message to any reader of your code as efficiently as possible. It pays because most often you will be the reader and when not you may have to explain the code to someone else.

Ian Whitlock <whitloi1@westat.com>

-----Original Message----- From: Vivek Annamalai [mailto:annamalaiv@HOTMAIL.COM] Sent: Tuesday, December 19, 2000 2:25 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Question on usage of data conversion functions in a Data Step;

Thanks to Shiling, John Goldberg, Patrick and Ian

I totally forgot about numric variables remain right justified while they are converted to characters using the put function. That explained the mystery behind the usage of best. as against explicitly best6. or just 6.

The usage of in= dataset option helps circumvent the problem. But I haven't got an answer as to why my original code doesn't produce the correct results.

Even replacing

if data_mon = . then data_mon = input(put(dm,6.),yymmn6.);

to

if dm ^= . then data_mon = input(put(dm,6.),yymmn6.);

solves the problem,which I found after getting your responses. There is no need for the in= data set option

The code without any changes produces the following result

id data_mon

11 199909 12 200010 15 200105 21 200009 22 200009 23 200009 24 200009

After making the above change the result looks like:

id data_mon

11 199909 12 200010 15 200105 21 200009 22 200007 23 200008 24 .

This begs the question on how the SAS supervisor is parsing the statements in both the cases.


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