BookmarkSubscribeRSS Feed
Lulus
Obsidian | Level 7

So I have these 101 variables and they are all continious.  they are, say, v1 v2 v3 v4.....v100 yes_No.

Now I wanted to seperate values on EACH VARIABLE to 10 groups.  for example, "age" for 10 groups,and "income" for 10 groups.

One observation can be in group one for V1 and group 6 for V2.

I know we can use proc rank to seperate out groups but I need help from there on.

So, how do I do this on the 100 varibales? Any macro suggestions?

What I mean is in the follwing, (Please ingonre any syntax errors, they are just to express my thoughts)

do order=1 to 100;

%let varlist=v1-v100;

%macro xx (  , order );

data data_new;

set data_old

keep &order from varlist;

run;

proc rank data=data_new; groups=10;

out=ranknew;

run;

data ranknew;

iv&order= {count(yes_no=1)/ count(yes_no=0)}

%mend xx;

and hopefully I will have the 100 new dataset all combined together.

Please help.  Thank you all very much in advance.

updated: by the way extra question, how to write a program quickly detect/seperate out which variables are continuous which are discrete quickly and label them?  thanks.

4 REPLIES 4
data_null__
Jade | Level 19

Are your variable names actually an enumerated list of are they something else?


Either way maybe this will get you started.

proc transpose data=sashelp.class(obs=0) out=vars;
   run;
proc sql noprint;
  
select
      _name_,
      catx(
'_','Rank',_name_)
     
into
      :vars separated by
' ',
      :ranks separated by
' '
  
from vars;
      ;
  
quit;
  
run;
%put NOTE: VARS=&Vars;
%put NOTE: RANKS=&ranks;

proc rank groups=3 data=sashelp.class out=classR;
   var &vars;
   ranks &ranks;
   run;
Astounding
PROC Star

Regarding "discrete" vs. "continuous" there is no standard way to do this.  You have to set up your own rules.  Here are some considerations.

If a variable is character, should it always be defined as discrete?

If a variable is always an integer, should it be defined as discrete?  If it takes on noninteger values, must it be defined as continuous?

If a variable takes on more than 30 different values, should it be defined as continuous?  (30 is an arbitrary cutoff, up to you to decide.)

No matter what set of rules you create, there will be exceptions that apply to a particular data set.  Zip codes take on thousands of values, yet should be considered discrete.  ICD9 codes should probably be stored as character, but if the numeric portion is stored separately it will contain decimal fractions.  Yet it is really discrete.  In the end, you will probably end up storing a list of variable names that should always be treated as continous (regardless of the rules that you set up), and a second list of variable names that should always be treated as discrete (again, regardless of other rules that you set up).

In a nutshell, if you had all the data values presented to you, and an infinite amount of time to work on the problem, how would you decide?

Good luck.

Lulus
Obsidian | Level 7

somtimes when you have hundreds or over 1000 variables you may wanna do that?

Astounding
PROC Star

No, you never wanna do that.  It's painstaking, tedious work.  But you have to do something.  So you do have to decide on what the rules will be.  You do have to recognize that the rules you set up will probably be inaccurate for some of the variables.  And you do have to decide whether you want to do something about that, vs. accept some inaccurate "decisions" that arise from your rules.

If the same data set will be used in this way many times over, the work that you put in up front will be useful every time.  It's up to you to decide how much work is worth the effort.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 541 views
  • 6 likes
  • 3 in conversation