Date: Sat, 11 Feb 2006 16:48:58 -0500
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: How to build Dynamic Variable names and values
Chandra,
In your array statement you have to declare a length that is at least as
long as the data the array will contain. If internal memory or
performance isn't an issue, you could simply make the length as long as
your widest variable.
The way you are using the substr function the number used is the starting
position of the digit contained in the variable name. If your variables
never contain any other numbers, rather than identifying the specific
number, you could use the ANYDIGIT function to instead of any specific
number.
Art
-----
On Sat, 11 Feb 2006 16:06:46 -0500, SUBSCRIBE SAS-L Chandra Gadde
<ddraj2015@GMAIL.COM> wrote:
>Hi Art,
>
>Thank you for your help. The code works fine with the existing variables
>and code.
>
>I have the following variables.
>
>amt_sld_upb_rstrtd(i), amt_sld_prem_disc(i), amt_sld_proceed(i), and
>end_sld_period. Where i = 1 to 13.
>
>If this is the scenario, how should I change the declaration format in the
>array to calculate the 3 new variables.
>
>I see that the total length of the variable amt_sld_prem_disc11 is 19. So
>that is the reason we have $19 in array. So if I have a variable
>amt_sld_upb_rstrtd12 then the format would be $20, right?
>
>How about the value "18" in if input(substr(vname(aaa),18),best.)
>=sld_uni_year then new_upb=aaa;
>Does it needs to be same if I use my above mentioned variables?
>
>Please suggest me.
>
>
>Chandra,
>
>Add a $19 in your array declaration. For example:
>
>data xx;
> input amt_sld_prem_disc11 amt_sld_prem_disc22 amt_sld_prem_disc33
> amt_sld_prem_disc44 amt_sld_prem_disc55 amt_sld_prem_disc66
> amt_sld_prem_disc77 amt_sld_prem_disc88 sld_uni_year amt_sld;
> cards;
>101.12 202 303 404 505 606 707 808 11 333
>111.23 212 313 414 515 616 717 818 22 876
>121.25 222 323 424 525 626 727 828 33 875
>131.25 232 333 434 535 636 737 838 44 765
>;
>run;
>data abc;
> set xx;
> array aaa $19 amt_sld_prem_disc:;
> do over aaa;
> if input(substr(vname(aaa),18),best.)=sld_uni_year then new_upb=aaa;
> end;
>run;
>
>Art
>---------
>On Sat, 11 Feb 2006 15:02:53 -0500, SUBSCRIBE SAS-L Chandra Gadde
><ddraj2015@GMAIL.COM> wrote:
>
>>Art,
>>
>>I tried with all possible numbers in my input statement. I am still
>>getting the same warings in log.
>>
>>I also tried Puddin's code..
>>
>>data rr;
>> input a11 a22 a33 a44 a55 a66 a77 a88 x;
>> array a(*) a:;
>> new_upb = a(mod(x, 10));
>>cards;
>>
>>But it is saying that
>>ERROR: Array subscript out of range at line 1735 column 14.
>>
>>I have two answers but I couldn't use none of them because of errors.
>>Would you please help me out?
>>
>>Thank you.
>>
>>
>>Chandra,
>>
>>I think you only have to adjust your input statement to account for the
>>new length of the variable names. For example,
>>
>>data abc;
>> set xx;
>> array aaa amt_sld_prem_disc:;
>> do over aaa;
>> if input(substr(vname(aaa),18),best.)=sld_uni_year then new_upb=aaa;
>> end;
>>run;
>>
>>Art
>>----------
>>On Sat, 11 Feb 2006 11:50:00 -0500, SUBSCRIBE SAS-L Chandra Gadde
>><ddraj2015@GMAIL.COM> wrote:
>>
>>>Hi Ya,
>>>
>>>Thank you, This works fine. But I in my work, I have variables such as
>>>
>>>amt_sld_prem_disc11 amt_sld_prem_disc22 amt_sld_prem_disc33
>>>amt_sld_prem_disc44 amt_sld_prem_disc55 amt_sld_prem_disc66
>>>amt_sld_prem_disc77 amt_sld_prem_disc88 instead of
>>>a11 a22 a33 a44 a55 a66 a77 a88.
>>>
>>>When I used this code..
>>>
>>>data xx;
>>>input amt_sld_prem_disc11 amt_sld_prem_disc22 amt_sld_prem_disc33
>>>amt_sld_prem_disc44 amt_sld_prem_disc55 amt_sld_prem_disc66
>>>amt_sld_prem_disc77 amt_sld_prem_disc88 sld_uni_year amt_sld;
>>>cards;
>>>101.12 202 303 404 505 606 707 808 11 333
>>>111.23 212 313 414 515 616 717 818 22 876
>>>121.25 222 323 424 525 626 727 828 33 875
>>>131.25 232 333 434 535 636 737 838 44 765
>>>;
>>>run;
>>>
>>>data abc;
>>>set xx;
>>>array aaa amt_sld_prem_disc:;
>>>do over aaa;
>>>if input(substr(vname(aaa),2),best.)=sld_uni_year then new_upb=aaa;
>>>end;
>>>run;
>>>
>>>
>>>This was my log...........
>>>
>>>
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>amt_sld_prem_disc11=101.12 amt_sld_prem_disc22=202
>amt_sld_prem_disc33=303
>>>amt_sld_prem_disc44=404 amt_sld_prem_disc55=505 amt_sld_prem_disc66=606
>>>amt_sld_prem_disc77=707 amt_sld_prem_disc88=808 sld_uni_year=11
>>>amt_sld=333 _I_=9 new_upb=. _ERROR_=1 _N_=1
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>amt_sld_prem_disc11=111.23 amt_sld_prem_disc22=212
>amt_sld_prem_disc33=313
>>>amt_sld_prem_disc44=414 amt_sld_prem_disc55=515 amt_sld_prem_disc66=616
>>>amt_sld_prem_disc77=717 amt_sld_prem_disc88=818 sld_uni_year=22
>>>amt_sld=876 _I_=9 new_upb=. _ERROR_=1 _N_=2
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>amt_sld_prem_disc11=121.25 amt_sld_prem_disc22=222
>amt_sld_prem_disc33=323
>>>amt_sld_prem_disc44=424 amt_sld_prem_disc55=525 amt_sld_prem_disc66=626
>>>amt_sld_prem_disc77=727 amt_sld_prem_disc88=828 sld_uni_year=33
>>>amt_sld=875 _I_=9 new_upb=. _ERROR_=1 _N_=3
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>NOTE: Invalid argument to function INPUT at line 215 column 4.
>>>amt_sld_prem_disc11=131.25 amt_sld_prem_disc22=232
>amt_sld_prem_disc33=333
>>>amt_sld_prem_disc44=434 amt_sld_prem_disc55=535 amt_sld_prem_disc66=636
>>>amt_sld_prem_disc77=737 amt_sld_prem_disc88=838 sld_uni_year=44
>>>amt_sld=765 _I_=9 new_upb=. _ERROR_=1 _N_=4
>>>NOTE: Mathematical operations could not be performed at the following
>>>places. The results of the operations have been set to missing values.
>>> Each place is given by: (Number of times) at (Line):(Column).
>>> 32 at 215:4
>>>NOTE: There were 4 observations read from the data set WORK.XX.
>>>NOTE: The data set WORK.ABC has 4 observations and 11 variables.
>>>NOTE: DATA statement used:
>>> real time 0.04 seconds
>>> cpu time 0.03 seconds
>>>
>>>Do you know what is going on here?
>>>
>>>Please suggest me.
>>>
>>>Thank you.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>for v8, you can try vname() + array:
>>>
>>>data xx;
>>>input a11 a22 a33 a44 a55 a66 a77 a88 x;
>>>array aaa a:;
>>>do over aaa;
>>>if input(substr(vname(aaa),2),best.)=x then new_upb=aaa;
>>>end;
>>>cards;
>>>101 202 303 404 505 606 707 808 11
>>>111 212 313 414 515 616 717 818 22
>>>121 222 323 424 525 626 727 828 33
>>>131 232 333 434 535 636 737 838 44
>>>;
>>>
>>>proc print;
>>>run;
>>>
>>>a11 a22 a33 a44 a55 a66 a77 a88 x new_upb
>>>
>>>101 202 303 404 505 606 707 808 11 101
>>>111 212 313 414 515 616 717 818 22 212
>>>121 222 323 424 525 626 727 828 33 323
>>>131 232 333 434 535 636 737 838 44 434
>>>
>>>
>>>Ya
>>>
>>>On Sat, 11 Feb 2006 01:42:10 +0000, toby dunn <tobydunn@HOTMAIL.COM>
>>wrote:
>>>
>>>>chandra ,
>>>>
>>>>If you have v9 you can do:
>>>>
>>>>new_upb = vvaluex('a'||left(x)) ;
>>>>
>>>>
>>>>
>>>>Toby Dunn
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>From: SUBSCRIBE SAS-L Chandra Gadde <ddraj2015@GMAIL.COM>
>>>>Reply-To: SUBSCRIBE SAS-L Chandra Gadde <ddraj2015@GMAIL.COM>
>>>>To: SAS-L@LISTSERV.UGA.EDU
>>>>Subject: How to build Dynamic Variable names and values
>>>>Date: Fri, 10 Feb 2006 20:02:01 -0500
>>>>
>>>>Hello Everyone,
>>>>
>>>>Here is my scenario.
>>>>
>>>>I have a dataset named dsn. Here is how it looks.
>>>>
>>>>a11 a22 a33 a44 a55 a66 a77 a88 x
>>>>101 202 303 404 505 606 707 808 11
>>>>111 212 313 414 515 616 717 818 22
>>>>121 222 323 424 525 626 727 828 33
>>>>131 232 333 434 535 636 737 838 44
>>>>
>>>>Now, I need to create a new variable calld new_upb such that
>>>>
>>>>new_upb = a(x);
>>>>
>>>>Meaning if the value of x = 11 then new_upb = a11 (a11=101 in our
case).
>>>>
>>>>In other words, New dataset will look like this
>>>>
>>>>a11 a22 a33 a44 a55 a66 a77 a88 x new_upb
>>>>101 202 303 404 505 606 707 808 11 101
>>>>111 212 313 414 515 616 717 818 22 212
>>>>121 222 323 424 525 626 727 828 33 323
>>>>131 232 333 434 535 636 737 838 44 434
>>>>
>>>>Could you please help me.
>>>>
>>>>Thank you.
|