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 (June 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 11 Jun 2008 20:48:46 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Subject:      Re: informats with array processing

On Wed, 11 Jun 2008 16:03:29 -0700, Nordlund, Dan (DSHS/RDA) <NordlDJ@DSHS.WA.GOV> wrote:

>> -----Original Message----- >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On >> Behalf Of Zach Peery >> Sent: Wednesday, June 11, 2008 3:18 PM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: informats with array processing >> >> Hi all, >> >> I am trying to add a leading zero to a series of number >> variables with the >> Zw.d informat. >> >> Have: >> var1 var2 var3 >> 7 6 1 >> 10 4 2 >> 5 13 4 >> >> Want: >> var1 var2 var3 >> 07 06 01 >> 10 04 02 >> 05 13 04 >> >> >> I can do it for one variable at a time, but it falls apart as >> soon as I >> start using array processing, as with the following: >> >> %let nvar = 3; >> data test; >> array var(&nvar.) var1-var&nvar.; >> do i = 1 to &nvar.; >> var(i) = put(var(i),z2.) >> end; >> run; >> >> Can anyone point out where I am going wrong? Thanks. Zach >> > >Zach, > >I see a couple places where you may be misunderstanding what is going here. >1. You don't read in any data in to create your test dataset. >2. your array name cannot have the same as "base" name as the series of variables following. Array name VAR must be diferent from VAR1-VAR3; you can use just V for example.

I don't think there is any such restriction. Naming an array "VAR" triggers a warning because there is a VAR function; that has nothing to do with the names of the constituent variables.

>3. you are missing a semi-colon after the assignment statement. >4. In SAS you can't change the type of a variable once it has been defined. In your log you should see some messages about character values being converted to numeric in reference to your assignment statement. You are converting your variable values to character strings with leading zeros which are then being converted back to numeric values on assignment. >5. You need to distinguish between how a variable is stored and how it is displayed. If you just want to display the values with leading zeros, you can do that by assigning a format to the variables. > >So, here is a revised verison of your program that incoporates the ideas above. > >data Have; > input var1 var2 var3; >datalines; >7 6 1 >10 4 2 >5 13 4 >; >run; >data want; > set have; > format var1 var2 var3 z2.; >run; >proc print; >run; > >If you want your variables to be character variables you can do something like this > >Data want; > set have; > array vnum(&nvar.) var1-var&nvar.; > array vchar(&nvar.) $ v1-v&nvar.; > do i = 1 to &nvar.; > vchar(i) = put(vnum(i),z2.); > end; >run; > >Hope this is helpful, > >Dan > >Daniel J. Nordlund >Washington State Department of Social and Health Services >Planning, Performance, and Accountability >Research and Data Analysis Division >Olympia, WA 98504-5204


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