From: Jindan Zhou on
My dataset contains the Variable:

Variable
Class1
Class2
Class3
Class4
Class5
Class6
Class7
Class8
Class9
Class10

I want to create a new numeric variable "count" such that
If Variable = "Class1" then count = 1;
ELSE if Variable = "Class2" then count =2;
....


This certainly does not look good, is there a more compact way?

Thanks,

Jindan

From: monal kohli on
count=substr(variable,6);

HTH
Mona

----- Original Message ----
From: Jindan Zhou <jindan(a)GMAIL.COM>
To: SAS-L(a)LISTSERV.UGA.EDU
Sent: Wednesday, September 5, 2007 3:35:26 PM
Subject: Creating new variables


My dataset contains the Variable:

Variable
Class1
Class2
Class3
Class4
Class5
Class6
Class7
Class8
Class9
Class10

I want to create a new numeric variable "count" such that
If Variable = "Class1" then count = 1;
ELSE if Variable = "Class2" then count =2;
....


This certainly does not look good, is there a more compact way?

Thanks,

Jindan


____________________________________________________________________________________
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
From: "Howard Schreier <hs AT dc-sug DOT org>" on
On Wed, 5 Sep 2007 12:49:58 -0700, monal kohli <k_monal_99(a)YAHOO.COM> wrote:

>count=substr(variable,6);

That gives a character result. To get a numeric, try something like this
(taken from code I posted for Jindan earlier):

line = input(substr(variable,6),2.);

>
>HTH
>Mona
>
>----- Original Message ----
>From: Jindan Zhou <jindan(a)GMAIL.COM>
>To: SAS-L(a)LISTSERV.UGA.EDU
>Sent: Wednesday, September 5, 2007 3:35:26 PM
>Subject: Creating new variables
>
>
>My dataset contains the Variable:
>
>Variable
>Class1
>Class2
>Class3
>Class4
>Class5
>Class6
>Class7
>Class8
>Class9
>Class10
>
>I want to create a new numeric variable "count" such that
>If Variable = "Class1" then count = 1;
>ELSE if Variable = "Class2" then count =2;
>...
>
>
>This certainly does not look good, is there a more compact way?
>
>Thanks,
>
>Jindan
>
>
>
____________________________________________________________________________________
>Luggage? GPS? Comic books?
>Check out fitting gifts for grads at Yahoo! Search
>http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
From: Dominc Mitchell on
Sorry I misread your message! Try that instead:


data x;

variable="class2";
count=prxchange('s/class(.*)/$1/i',-1,variable)*1;
proc print data=x;
run;





-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Jindan
Zhou
Sent: Wednesday, September 05, 2007 15:35
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Creating new variables

My dataset contains the Variable:

Variable
Class1
Class2
Class3
Class4
Class5
Class6
Class7
Class8
Class9
Class10

I want to create a new numeric variable "count" such that
If Variable = "Class1" then count = 1;
ELSE if Variable = "Class2" then count =2;
....


This certainly does not look good, is there a more compact way?

Thanks,

Jindan
From: Dominc Mitchell on
Hi Jindan,


You could do something like:

array class class1-class10;

count=0;
do over class;
if class ne . then count+1;
end;


Another way is simply:

nmiss=10-nmiss(of class1-class10); *nmiss counts the number of missing;

where 10 is your number of variables.


Both methods assume that there are no holes in the data say non-missing data
for class1 to class. Otherwise the count variable won't represent the last
non-missing variable.


Dominic.








-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Jindan
Zhou
Sent: Wednesday, September 05, 2007 15:35
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Creating new variables

My dataset contains the Variable:

Variable
Class1
Class2
Class3
Class4
Class5
Class6
Class7
Class8
Class9
Class10

I want to create a new numeric variable "count" such that
If Variable = "Class1" then count = 1;
ELSE if Variable = "Class2" then count =2;
....


This certainly does not look good, is there a more compact way?

Thanks,

Jindan
 | 
Pages: 1
Prev: Reg: Sort in Proc Report
Next: Oracle BI