f



vname, assigning character variable to itself

Hi group,

I would like to get the names of all variables ending in "MTRM" using
something like this:

data _null_;
set &_pricedat;
length mtrm $200.;
mtrm='';
if _n_=1 then do;
array vars(*) _numeric_;
   do i=1 to dim(vars);
      temp=reverse(vname(vars(i)));
      put temp=;
      if upcase(substr(left(temp),1,4))="MRTM" then mtrm = mtrm || ' '
|| vname(vars(i));
      put mtrm= ;
   end;
call symput('mtrm',mtrm);
end;
if _n_ ge 1 then stop;
run;

%put MTMR = &MTRM;

The weak point appears to be the assignment
mtrm = mtrm || ' ' || vname(vars(i));

MTRM comes back empty, even though the decision (upcase ..) works.

How can I do this? I am probably missing something quite simple ...

Regards,

Janis Jekabsons
0
6/24/2003 10:41:42 AM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

3 Replies
981 Views

Similar Articles

[PageSpeed] 34

Hi Janis

Haven't got manuals here, but have a read in the BASE SAS Reference
Guide (I think) about dictionary tables. I suspect that you will find
using SASHELP.VTABLE (again I think this is the one that contains table
fields) to be an easier approach.

Don

Janis Jekabsons wrote:
>
> Hi group,
>
> I would like to get the names of all variables ending in "MTRM" using
> something like this:
>
> data _null_;
> set &_pricedat;
> length mtrm $200.;
> mtrm='';
> if _n_=1 then do;
> array vars(*) _numeric_;
>    do i=1 to dim(vars);
>       temp=reverse(vname(vars(i)));
>       put temp=;
>       if upcase(substr(left(temp),1,4))="MRTM" then mtrm = mtrm || ' '
> || vname(vars(i));
>       put mtrm= ;
>    end;
> call symput('mtrm',mtrm);
> end;
> if _n_ ge 1 then stop;
> run;
>
> %put MTMR = &MTRM;
>
> The weak point appears to be the assignment
> mtrm = mtrm || ' ' || vname(vars(i));
>
> MTRM comes back empty, even though the decision (upcase ..) works.
>
> How can I do this? I am probably missing something quite simple ...
>
> Regards,
>
> Janis Jekabsons

--
Don Stanley, B.SC, Dip O.R.S, MNZCS
Author:: Beyond the obvious with SAS Screen Control Language.
Author:: Solutions for your GUI Applications Development Using SAS/AF
FRAME Technology
http://www.syswaregroup.com , http://homepages.rootsweb.com/~ashluke
0
don_stanley (190)
6/24/2003 11:17:26 AM
Hi Janis

The reason this is ending up with MTRM being blank is the line you
marked as suspicious, and it is due to the fact that MTRM is 200 chars
long and you are attempting to do the concatenation to the end of that
padded string. Use mtrm = trim(left(mtrm))|| ' ' || vname(vars(i)); and
all should be fine here.

Don

Janis Jekabsons wrote:
>
> Hi group,
>
> I would like to get the names of all variables ending in "MTRM" using
> something like this:
>
> data _null_;
> set &_pricedat;
> length mtrm $200.;
> mtrm='';
> if _n_=1 then do;
> array vars(*) _numeric_;
>    do i=1 to dim(vars);
>       temp=reverse(vname(vars(i)));
>       put temp=;
>       if upcase(substr(left(temp),1,4))="MRTM" then mtrm = mtrm || ' '
> || vname(vars(i));
>       put mtrm= ;
>    end;
> call symput('mtrm',mtrm);
> end;
> if _n_ ge 1 then stop;
> run;
>
> %put MTMR = &MTRM;
>
> The weak point appears to be the assignment
> mtrm = mtrm || ' ' || vname(vars(i));
>
> MTRM comes back empty, even though the decision (upcase ..) works.
>
> How can I do this? I am probably missing something quite simple ...
>
> Regards,
>
> Janis Jekabsons

--
Don Stanley, B.SC, Dip O.R.S, MNZCS
Author:: Beyond the obvious with SAS Screen Control Language.
Author:: Solutions for your GUI Applications Development Using SAS/AF
FRAME Technology
http://www.syswaregroup.com , http://homepages.rootsweb.com/~ashluke
0
don_stanley (190)
6/24/2003 11:19:44 AM
add a trim to mtrm==>

if upcase(substr(left(temp),1,4))="MRTM" then mtrm = trim(mtrm) || ' '
 || vname(vars(i));

You can also use SCL function in datastep (look after functions: open,
attrn, varname, close).
or the SASHELP.VCOLUMN view.
or ODS with proc contents
or proc contents...

Xavier


Janis.Jekabsons@dresdner-bank.com (Janis Jekabsons) wrote in message news:<f6ed644e.0306240241.16875a34@posting.google.com>...
> Hi group,
> 
> I would like to get the names of all variables ending in "MTRM" using
> something like this:
> 
> data _null_;
> set &_pricedat;
> length mtrm $200.;
> mtrm='';
> if _n_=1 then do;
> array vars(*) _numeric_;
>    do i=1 to dim(vars);
>       temp=reverse(vname(vars(i)));
>       put temp=;
>       if upcase(substr(left(temp),1,4))="MRTM" then mtrm = mtrm || ' '
> || vname(vars(i));
>       put mtrm= ;
>    end;
> call symput('mtrm',mtrm);
> end;
> if _n_ ge 1 then stop;
> run;
> 
> %put MTMR = &MTRM;
> 
> The weak point appears to be the assignment
> mtrm = mtrm || ' ' || vname(vars(i));
> 
> MTRM comes back empty, even though the decision (upcase ..) works.
> 
> How can I do this? I am probably missing something quite simple ...
> 
> Regards,
> 
> Janis Jekabsons
0
xav_x (29)
6/24/2003 2:40:06 PM
Reply:

Similar Artilces:

Re: vname, assigning character variable to itself
Don, Thanks for the quick reply. In this respect, I made this observation/test: 1 data one; 2 length a c $4. b$8.; 3 a="WWWW"; b=c||' '|| a; 4 put b=; 5 run; NOTE: Variable C is uninitialized. B=WWW NOTE: The data set WORK.ONE has 1 observations and 3 variables. NOTE: DATA statement used: real time 0.02 seconds cpu time 0.01 seconds Actually, I was expecting B= WWW. This must be happening somewhere since the fourth "W" _is_ gone. I could have mentioned in my original post, that I ...

Antwort: vname, assigning character variable to itself
Hi Janis, if I got your problem right, you want to have a macrovar containing a space delimited list of all variable names beginning with "MTRM". I'd go with the dictionary tables and proc sql. My example assumes that &pricedat is combining libref and Data set name. data test; array mtrm a_mtrm b_mtrm c_mtrm d_mtrm e_mtrm f_mtrm g_mtrm h_mtrm_in_the_middle mtrm_at_beginning ; do i = 1 to 10; do over mtrm; mtrm = ranuni(1); end; output; end; run; %let _pricedat = work.test; proc sql noprint; select name into :mtrm separated by ' ' ...

Assign variables to a new variable based on variable names in SAS
Thank so much Nagakumar Sridhar and Fehd, Ronald J. for answering my previous question. However I was not clear in the original post. I modified my phrasing and the new version is below: I have met the following problem and I need your expert help. The variable names in the data set looks like this: a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n Please note that "quarter" numbers in "a_****q*" variables may not be continuous, i.e. there might be a missing quarter. and n can have the value of any quarter for while a_quarter exists, say "1995q3", "...

Re: Assign variables to a new variable based on variable names in SAS
How about this? (I may not have enough &'s in this) -Venita %macro change (filename); data file2; set file1; %do yr = 1990 %to 2003; %do qtr = 1 %to 4; if n= "&&yr.q&qtr" then new_a = a_&yr.q&qtr ; %end; %end; %mend; %change (filename=name); > if n="1995q3" then new_a=a_1995q3; > > ---------- > From: W M[SMTP:mwx74@HOTMAIL.COM] > Reply To: W M > Sent: Thursday, January 15, 2004 2:02 PM > To: SAS-L@LISTSERV.UGA.EDU > S...

Re: Assign variables to a new variable based on variable names in SAS #4
On Thu, 15 Jan 2004 11:02:05 -0800, W M <mwx74@HOTMAIL.COM> wrote: >I have met the following problem and I need your expert help. >The variable names in the data set looks like this: > >a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n > Is there a way like > >new_a=a_{value of n} ? > >Because of the compilation of data step, you cannot do > >data new; set old; >call symput("name", n); >new_a=a_&n; (wrong !) >run; Hi, V, Following up on Paul (Choate)'s idea, this seems to work. This would serve as an example of putting an...

Re: Assign variables to a new variable based on variable names in SAS #8
Here's a no-macro Version 9 technique which will work under some circumstances: data _null_; a_1995q3 = 1995.3; a_1995q4 = 1995.4; a_1997q1 = 1997.1; a_2003q4 = 2003.4; n = "1995q4"; new_a = input(vvaluex('a_'||n),32.); put new_a=; run; Result: new_a=1995.4 Because there is conversion from numeric to character and back to numeric, this may be slow, there may be undesirable rounding, and (if the format and the informat do not mirror each other well enough) there may be errors. To illustrate try running with either of these statements added...

Re: Assign variables to a new variable based on variable names in SAS #3
Here's a solution that builds a list of subscripts in macro variables named like the 'a_' columns in the input dataset. 'a_' fields are referenced by the subscript from the array they're defined to be part of: data stuff; a_2003q4 = 44; a_2003q1 = 11; a_2003q2 = 22; a_2003q3 = 33; n = 'a_2003q3'; run; proc sql noprint; create table columns as select name from sashelp.vcolumn where libname = 'WORK' and memname = 'STUFF' and name eqt 'a_' order by name ; select compbl('...

Re: Assign variables to a new variable based on variable names in SAS #6
Hi, Richard, Your data step, "monkeyshines" is one of the prettest I have ever seen. Really nice. The to-the-point array statement using the variable name wild character (":"); use of lbound() hbound() functions; use of _i_ for index variable; short but intuitive variable and array names like aVars, aBase, and aMap; use of intnx and intck functions, reading the returned variable name with ??yyq6. format, anticipation of range checking, and all the work was done in essentially a single line!("a_new = aVars[aMap[qtrIndex]];") ... I learn a lot just by reading your...

Re: Assign variables to a new variable based on variable names in SAS #2
V - http://v8doc.sas.com/sashtml/macro/z0210258.htm You can create a macro variable with the SYMPUT routine and use RESOLVE to resolve it in the same DATA step. %let event=Holiday; %macro date; New Year %mend date; data test; length var1-var3 $ 15; when='%date'; var1=resolve('&event'); /* macro variable reference */ var2=resolve('%date'); /* macro invocation */ var3=resolve(when); /* DATA step variable with macro invocation */ put var1= var2= var3=; run; hth Paul Choate DDS Data Extraction (916) 654-2160 -----Original Message-----...

Re: Assign variables to a new variable based on variable names in SAS #5
Hi Chang & V - I'm confused as usual - did you mean this? 142 data one; 143 a_1995q3 = 1; 144 a_1995q4 = 2; 145 a_1997q1 = 3; 146 a_2003q4 = 5; 147 n = "2003q4"; 148 run; NOTE: The data set WORK.ONE has 1 observations and 5 variables. NOTE: DATA statement used: real time 0.01 seconds cpu time 0.01 seconds 149 150 data two; 151 set one; 152 call symput('n', n); 153 new_a = 'a_'||resolve(n); 154 put new_a=; 155 run; new_a=a_2003q4 NOTE: There were 1 observations read from the data set WORK.ONE...

Re: Assign variables to a new variable based on variable names in SAS #7
Chang, I agree with your assessment of Richard's code. I especially liked that he offered it without any chest pounding! Joe -----Original Message----- From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM> Sent: Jan 16, 2004 11:19 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Assign variables to a new variable based on variable names in SAS Hi, Richard, Your data step, "monkeyshines" is one of the prettest I have ever seen. Really nice. The to-the-point array statement using the variable name wild character (":"); use of lbound() hbound() f...

Assign variables to a new variable dynamically in SAS
Dear all, I have met the following problem and I need your expert help. The variable names in the data set looks like this: a1 a3 a7 ........... a20 n Now I want to do this: if n=1 then new_a=a1; if n=2 then new_a=a2; ..... if n=20 then new_a=a20; Is there a simpler way using macro to do this in SAS ? Because I have several other variable sets to do, say b, c, d, .... Many thanks, V. On 15 Jan 2004 08:40:43 -0800, mwx74@hotmail.com (W M) wrote: >Dear all, > >I have met the following problem and I need your expert help. >The variable names in the data set looks like thi...

Re: Assign variables to a new variable dynamically in SAS
> From: W M [mailto:mwx74@HOTMAIL.COM] > I have met the following problem and I need your expert help. > The variable names in the data set looks like this: > > a1 a3 a7 ........... a20 n > > Now I want to do this: > > if n=1 then new_a=a1; > if n=2 then new_a=a2; > .... > if n=20 then new_a=a20; > > Is there a simpler way using macro to do this in SAS ? > Because I have several other variable sets to do, say b, c, d, .... what arrays were made for: DATA New; array A (*) a1--a20; set Old; New_A = A(N); the value of N in 1:20 is the index of...

how to assign a same variable into two different new variables in SAS
Hi, is it possible to re-assign a same variable into two different two variables, as a result of a revision/regruping of codes in the stocklist as shown using proc format... proc format; value $stock '34211'='34312' '34211'='34124'' '31412','33213'='23412' '23456'='56789' ; i got an error in the 1st two lines cos it seems like it can't read in the same old code twice assigned in this manner,while the 3rd line is ok...so it there any p...

Web resources about - vname, assigning character variable to itself - comp.soft-sys.sas

South Carolina Legislators Vote to Cut University Funding for Assigning LGBT Books
Republican legislators in South Carolina want to teach two state universities a lesson for assigning books with LGBT themes.

Pitfall of Scrum: Assigning Tasks
Learn more about our Scrum and Agile training sessions on WorldMindware.com Even though the concept of self-organizing teams has been around ...

Google celebrates Teacher Appreciation Week by assigning new features to Classroom
The first full week of May is designated in the U.S. as Teacher Appreciation Week. It happens to be this week. And in honor of the occasion, ...

Assigning Odds to Every Potential Buccaneers 1st-Round Pick
The NFL draft is the most elaborate gambling enterprise in existence. Obviously, there is considerable skill involved in developing an NFL prospect, ...

Assigning Blame
Never forget: conservatives tortured Jesus and then murdered him Conservatives' infatuation with torture has a long sordid history. Sunday when ...

Assigning blame for new, more costly medical plan, Corporate points to Washington's favorite piñata
I'm always skeptical when companies make broad statements without citing dollar amounts or other hard numbers to back them up. That's why Corporate's ...

Programatically assigning a Customer Group in Magento
Magento’s Customer Groups give you the ability to offer different pricing and promotions to customers based upon their grouping. This grouping ...

Selfie With Parents’ Sex Toys? Alameda Teacher Accused Of Assigning Bizarre Extra Credit For Sophomores ...
Parents of students at an Alameda high school want a teacher fired after they say he sent them home with an extra credit assignment of finding ...


RG3 confirms progress, avoids assigning blame
In an exclusive interview with Redskins Nation, RG3 discusses his recovery and his desire to move past assigning blame.

Resources last updated: 2/3/2016 7:35:10 AM