Google Groups Home
Help | Sign in
Keeping Series of variables - tricky
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Eash  
View profile
 More options May 11 2006, 5:10 am
Newsgroups: comp.soft-sys.sas
From: "Eash" <easw...@gmail.com>
Date: 11 May 2006 02:10:41 -0700
Local: Thurs, May 11 2006 5:10 am
Subject: Keeping Series of variables - tricky
Hi All,

when I have  variables life Live,Love,Learn  - I used   :    Keep L:;

But When I have Fight,Right and Tight - Is it possible to Use :ight??

If Yes, can you Guide me? I tried :ight - and got the scary brown lines
in the log!!

Note : the example is just sample. In reality , I have 100+ variables
ending with _SCORE, among 382 Variables!!! :( just want to Keep only
the variables ending with _SCORE! :(

cheerz
EasH


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gerhard Hellriegel  
View profile
 More options May 11 2006, 9:40 am
Newsgroups: comp.soft-sys.sas
From: ghellr...@T-ONLINE.DE (Gerhard Hellriegel)
Date: Thu, 11 May 2006 09:40:29 -0400
Local: Thurs, May 11 2006 9:40 am
Subject: Re: Keeping Series of variables - tricky
What you can do:
select the variables you want from SASHELP.VTABLES into macro variables and
assemble your keep list from there...

something like:

proc sql;
  create table vars as
    select * from sashelp.vcolumn
    where libname= .... and memname= ...
 ;
quit;
%let no=0;
data _null_;
  set vars;
  where name=:"L";
  call symput("no",_n_);
  call symput("var"!!compress(put(_n_,8.)),name);
run;

%macro x;
  data ....
    ...
    keep
   %do i=1 to &no;
      &&var&i
   %end;
   ;
  ....
  run;
%mend;
%x;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Yount  
View profile
 More options May 11 2006, 9:44 am
Newsgroups: comp.soft-sys.sas
From: Eric.Yo...@RTP.PPDI.COM (Eric Yount)
Date: Thu, 11 May 2006 09:44:05 -0400
Local: Thurs, May 11 2006 9:44 am
Subject: Re: Keeping Series of variables - tricky
Sorry, : only works at the end of variables.  Something like this
(untested) might work:

proc sql;
    select memname into :vars
    from dictionary.members
    where libname = 'YOURLIB' AND memname like '%_SCORE';
quit;

data two;
    set one;
    keep &vars;
run;

Hope this helps,
Eric


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Groeneveld  
View profile
 More options May 11 2006, 9:39 am
Newsgroups: comp.soft-sys.sas
From: jim2s...@YAHOO.CO.UK (Jim Groeneveld)
Date: Thu, 11 May 2006 09:39:22 -0400
Local: Thurs, May 11 2006 9:39 am
Subject: Re: Keeping Series of variables - tricky
Hi Eash,

I don't think SAS can rhyme. You'll have to analyze all the variable names
by yourself and build a (macro) list of names to use.

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Venky Chakravarthy  
View profile
 More options May 11 2006, 9:36 am
Newsgroups: comp.soft-sys.sas
From: swo...@HOTMAIL.COM (Venky Chakravarthy)
Date: Thu, 11 May 2006 09:36:18 -0400
Local: Thurs, May 11 2006 9:36 am
Subject: Re: Keeping Series of variables - tricky

EasH,

The LIKE operator and the use of metadata are needed to arrive at your keep
list. There are several examples in the archives, but briefly this is how
you would go about it.

data test ;
  retain a_score a1_score b_score score score2 1 ;
run ;

proc sql noprint ;
  select trim(name) into : keeplist separated by " "
    from dictionary.columns
    where libname = "WORK" and
          memname = "TEST" and
          name like '%_SCORE';
quit ;

%put <&keeplist> ;

data _score ;
  set test (keep=&keeplist) ;
run ;

Venky Chakravarthy


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"data _null_;"  
View profile
 More options May 11 2006, 10:01 am
Newsgroups: comp.soft-sys.sas
From: datan...@GMAIL.COM ("data _null_;")
Date: Thu, 11 May 2006 10:01:52 -0400
Local: Thurs, May 11 2006 10:01 am
Subject: Re: Keeping Series of variables - tricky
You have the right idea but you are working too hard to get the list
of variable names.

data work.tricky;
   retain Fight Right Tight Weight Height 0;
   stop;
   run;

%global keepList;
proc sql noprint;
   select name into :keepList separated by ' '
   from dictionary.columns
   where libname='WORK' and memname='TRICKY'
   and name like '_ight'
   ;
   quit;
   run;
%put NOTE: Keeplist = &keeplist;

On 5/11/06, Gerhard Hellriegel <ghellr...@t-online.de> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby dunn  
View profile
 More options May 11 2006, 10:16 am
Newsgroups: comp.soft-sys.sas
From: tobyd...@HOTMAIL.COM (toby dunn)
Date: Thu, 11 May 2006 14:16:00 +0000
Subject: Re: Keeping Series of variables - tricky
Eash ,

I havent seen this original post so I am going to highjack Gerhards ( hope
you dont mind Gerhard).

You want to be able to specify a list of variables that end with a certain
set of characters.

data one ;
A_Study = 1 ;
B_Study = 1 ;
C_Study = 1 ;
D_Study = 1 ;

A_Test  = 1 ;
B_Test  = 1 ;
C_Test  = 1 ;
D_Test  = 1 ;

run ;

proc sql noprint ;
  select name into : KeepList separated by ' '
   from dictionary.columns
    where Libname = 'WORK'
      and Memname = 'ONE'
      and upcase(Name) like '%_STUDY' ;
quit ;

data one ;
set one ( keep = &KeepList ) ;
run ;

proc contents
data = one ;
run ;

Should do it.  How you use the macro var Keeplist to keep you wanted vars is
up to you I used another data step but I presume one could just as easily
use proc datasets.

Toby Dunn

From: Gerhard Hellriegel <ghellr...@T-ONLINE.DE>
Reply-To: Gerhard Hellriegel <ghellr...@T-ONLINE.DE>
To: SA...@LISTSERV.UGA.EDU
Subject: Re: Keeping Series of variables - tricky
Date: Thu, 11 May 2006 09:40:29 -0400

What you can do:
select the variables you want from SASHELP.VTABLES into macro variables and
assemble your keep list from there...

something like:

proc sql;
   create table vars as
     select * from sashelp.vcolumn
     where libname= .... and memname= ...
  ;
quit;
%let no=0;
data _null_;
   set vars;
   where name=:"L";
   call symput("no",_n_);
   call symput("var"!!compress(put(_n_,8.)),name);
run;

%macro x;
   data ....
     ...
     keep
    %do i=1 to &no;
       &&var&i
    %end;
    ;
   ....
   run;
%mend;
%x;

On Thu, 11 May 2006 02:10:41 -0700, Eash <easw...@GMAIL.COM> wrote:

 >Hi All,
 >
 >when I have  variables life Live,Love,Learn  - I used   :    Keep L:;
 >
 >But When I have Fight,Right and Tight - Is it possible to Use :ight??
 >
 >If Yes, can you Guide me? I tried :ight - and got the scary brown lines
 >in the log!!
 >
 >Note : the example is just sample. In reality , I have 100+ variables
 >ending with _SCORE, among 382 Variables!!! :( just want to Keep only
 >the variables ending with _SCORE! :(
 >
 >cheerz
 >EasH

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"data _null_;"  
View profile
 More options May 11 2006, 11:01 am
Newsgroups: comp.soft-sys.sas
From: datan...@GMAIL.COM ("data _null_;")
Date: Thu, 11 May 2006 11:01:32 -0400
Local: Thurs, May 11 2006 11:01 am
Subject: Re: Keeping Series of variables - tricky
As you are looking for values that contain one of the LIKE operator's,
operator.  You will need to know about the ESCAPE option.  See below.

data work.tricky;
   retain Fight Right Tight Weight Height 0;
   retain Fight_SCORE Right_SCORE Tight_SCORE Weight_SCORE Height_SCORE 0;
   retain FightSCORE RightSCORE TightSCORE WeightSCORE HeightSCORE 0;
   stop;
   run;

%global keepList;
%let keepList=;
proc sql noprint;
   select name into :keepList separated by ' '
   from dictionary.columns
   where libname='WORK' and memname='TRICKY'
   and name like '%\_SCORE' escape '\'
   ;
   quit;
   run;
 %put NOTE: Keeplist = &keeplist;

On 5/11/06, Eash <easw...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Venky Chakravarthy  
View profile
 More options May 11 2006, 12:32 pm
Newsgroups: comp.soft-sys.sas
From: swo...@HOTMAIL.COM (Venky Chakravarthy)
Date: Thu, 11 May 2006 12:32:19 -0400
Local: Thurs, May 11 2006 12:32 pm
Subject: Re: Keeping Series of variables - tricky

On Thu, 11 May 2006 11:01:32 -0400, data _null_; <datan...@GMAIL.COM> wrote:
>As you are looking for values that contain one of the LIKE operator's,
>operator.  You will need to know about the ESCAPE option.  See below.

Did not know such an option existed in this context. Learnt something new
today.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Groeneveld  
View profile
 More options May 12 2006, 3:48 am
Newsgroups: comp.soft-sys.sas
From: jim2s...@YAHOO.CO.UK (Jim Groeneveld)
Date: Fri, 12 May 2006 03:48:36 -0400
Local: Fri, May 12 2006 3:48 am
Subject: Re: Keeping Series of variables - tricky
Hi Eash,

Well, two other alternatives to let SAS rhyme are given in the example:

=============================================================
DATA Test;
  abcde_score = 1;
  fghij_value = 2;
  bacde_score = 3;
  Score       = 4;
RUN;

%LET KeepList = ; %* Create GLOBAL macro variable KeepList;

* Alternative X;
proc sql noprint;
  select trim(name) into : keeplist separated by " "
    from dictionary.columns
    where libname = "WORK" and
    memname = "TEST" and
    UPCASE(SUBSTR(REVERSE(TRIM(name)),1,6)) EQ 'EROCS_';
quit ;

%PUT Alternative X: KeepList=&KeepList;

%LET KeepList = ; %* you never know......;

* Alternative X+1;
proc sql noprint;
  select trim(name) into : keeplist separated by " "
    from dictionary.columns
    where libname = "WORK" and
    memname = "TEST" and
    INDEX(name,'_') AND
    UPCASE(SCAN(name,-1,'_')) EQ 'SCORE';
quit ;

%PUT Alternative X+1: KeepList=&KeepList;
=========================================================

The first one (X) obviously generates the note for name Score:
NOTE: Invalid argument 3 to function SUBSTR. Missing values may be generated.

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
yxz  
View profile
 More options May 12 2006, 3:49 pm
Newsgroups: comp.soft-sys.sas
From: yxz <y...@nomail.com>
Date: Fri, 12 May 2006 15:49:36 -0400
Local: Fri, May 12 2006 3:49 pm
Subject: Re: Keeping Series of variables - tricky
Yet another alternative using perl regular expression:

data test;
  a1_score  = 1;
  a2_value  = 2;
  a3_sCore  = 3;
  a4Score   = 4;
  a5_scores = 5;
run;

%let keeplist=;

proc sql noprint;
  select name into : keeplist separated by " "
    from dictionary.columns
    where libname = "WORK" and
    memname = "TEST" and
    prxmatch(prxparse("/_score\b/i"), name);
quit;

%put &keeplist.;

On 11 May 2006 02:10:41 -0700, "Eash" <easw...@gmail.com> wrote:


    Reply to author    Forward  
You must