|
|
using proc format and case statement
Dear SAS users and experts,
I have a situation where I have to assign a different value for
different condition in the proc format
for eg:
data set is as follows
x a b
1 2 1
1 2 2
1 2 3
1 1 1
1 1 2
1 1 3
1 1 4
if a = 2 and b = 1 then c = 'bl'
if a = 1 and b = 1 then c = 'ont'
I have different set of conditions, I thought of doing creating format
for b values but it varies depending on a variable.
Hence I was just wondering can I use case in the proc format or if
conditions some thing like that
your input is appreciated.
thank you
|
|
0
|
|
|
|
Reply
|
saslearn007 (22)
|
4/2/2007 1:06:53 PM |
|
If you already wrote your IF ELSE IF statements, it's not an obligation to
rewrite a proc format, no ?
well, perhaps you can create a variable that merge a b , create a format in
relation to this variable and do a D variable with it.
x a b c
1 2 1 21
1 2 2 22
....
proc format;
value test
21='bl'
22='ont'
....
and now use a d=Put(c,test.);
HTH
Stephane.
**************************
Selon saslearn007@GMAIL.COM:
> Dear SAS users and experts,
>
> I have a situation where I have to assign a different value for
> different condition in the proc format
>
> for eg:
>
> data set is as follows
>
> x a b
>
> 1 2 1
> 1 2 2
> 1 2 3
> 1 1 1
> 1 1 2
> 1 1 3
> 1 1 4
>
> if a = 2 and b = 1 then c = 'bl'
> if a = 1 and b = 1 then c = 'ont'
>
> I have different set of conditions, I thought of doing creating format
> for b values but it varies depending on a variable.
>
> Hence I was just wondering can I use case in the proc format or if
> conditions some thing like that
>
> your input is appreciated.
>
> thank you
>
|
|
0
|
|
|
|
Reply
|
scolas (213)
|
4/2/2007 1:18:39 PM
|
|
saslearn007@GMAIL.COM wrote:
>
>Dear SAS users and experts,
>
>I have a situation where I have to assign a different value for
>different condition in the proc format
>
>for eg:
>
>data set is as follows
>
>x a b
>
>1 2 1
>1 2 2
>1 2 3
>1 1 1
>1 1 2
>1 1 3
>1 1 4
>
>if a = 2 and b = 1 then c = 'bl'
>if a = 1 and b = 1 then c = 'ont'
>
>I have different set of conditions, I thought of doing creating format
>for b values but it varies depending on a variable.
>
>Hence I was just wondering can I use case in the proc format or if
>conditions some thing like that
>
>your input is appreciated.
>
>thank you
There are a lot of options here. But making a choice about a 'good'
option is going to require some information from *you*.
What *exactly* are your 'a' and 'b' variables? Character or numeric?
What are their max and min values? What's their cardinality?
How big is the data set you need to work with? How many records?
How many variables?
What is the purpose of your 'C' variable? What are you going to do with
it once you have it?
Depending on your answers, the solution might be a simple SELECT
or PROC FORMAT made from welding your A and B together in some
meaningful way. Or it might be more complex. It might be better
to use a hash or a set of indexed look-up tables. I can't tell from way
over here. So write back to SAS-L with more info.
HTH,
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330
_________________________________________________________________
Download Messenger. Join the i�m Initiative. Help make a difference today.
http://im.live.com/messenger/im/home/?source=TAGHM_APR07
|
|
0
|
|
|
|
Reply
|
davidlcassell (5578)
|
4/3/2007 5:01:59 AM
|
|
saslearn007@gmail.com wrote to me personally instead of to SAS-L:
>
>On Apr 3, 1:01 am, davidlcass...@MSN.COM (David L Cassell) wrote:
> > saslearn...@GMAIL.COM wrote:
> >
> > >Dear SAS users and experts,
> >
> > >I have a situation where I have to assign a different value for
> > >different condition in the proc format
> >
> > >for eg:
> >
> > >data set is as follows
> >
> > >x a b
> >
> > >1 2 1
> > >1 2 2
> > >1 2 3
> > >1 1 1
> > >1 1 2
> > >1 1 3
> > >1 1 4
> >
> > >if a = 2 and b = 1 then c = 'bl'
> > >if a = 1 and b = 1 then c = 'ont'
> >
> > >I have different set of conditions, I thought of doing creating format
> > >for b values but it varies depending on a variable.
> >
> > >Hence I was just wondering can I use case in the proc format or if
> > >conditions some thing like that
> >
> > >your input is appreciated.
> >
> > >thank you
> >
> > There are a lot of options here. But making a choice about a 'good'
> > option is going to require some information from *you*.
> >
> > What *exactly* are your 'a' and 'b' variables? Character or numeric?
> > What are their max and min values? What's their cardinality?
> >
> > How big is the data set you need to work with? How many records?
> > How many variables?
> >
> > What is the purpose of your 'C' variable? What are you going to do with
> > it once you have it?
> >
> > Depending on your answers, the solution might be a simple SELECT
> > or PROC FORMAT made from welding your A and B together in some
> > meaningful way. Or it might be more complex. It might be better
> > to use a hash or a set of indexed look-up tables. I can't tell from way
> > over here. So write back to SAS-L with more info.
> >
> > HTH,
> > David
> > --
> > David L. Cassell
> > mathematical statistician
> > Design Pathways
> > 3115 NW Norwood Pl.
> > Corvallis OR 97330
> >
> > _________________________________________________________________
> > Download Messenger. Join the i'm Initiative. Help make a difference
>today.http://im.live.com/messenger/im/home/?source=TAGHM_APR07- Hide quoted
>text -
> >
> > - Show quoted text -
>
>Hi David,
>
>I found a work around for my problem. I was trying to give u dummy
>example. Which did not made any sense.
>
>But when I was reading your reply, you mentioned the following
>statement which really interested me.
>
>It might be better
> > to use a hash or a set of indexed look-up tables.
>
>Do you have any info on these two. Please send me any links or
>examples.
>
>thanks
>
First, always write to SAS-L. I may be off the list for vacation or work or
a bender or something.
Second, always write to SAS-L. I only found this because I happened to
look through my spam filters today. Yes, it went into my spam filters.
So it very nearly was never seen again by mortal man.
Third, always write to SAS-L. The combined expertise on this list dwarfs
my own. You'll always get answers that are at least as good as mine,
since you will at least get mine. And you'll typically get answers that are
WAAAAY better, especially on something like this.
For refs on this stuff, I would start with the SUGI papers at SAS - or at
lexjansen.com, which is better for searching. Either way, grab the
Art Carpenter paper on look-up tables in SAS, and then find Gregg Snell's
tutorial on hashes in SAS 9 .
Then turn to the SAS-L archives and search on these subjects.
HTH,
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330
_________________________________________________________________
Mortgage rates near historic lows. Refinance $200,000 loan for as low as
$771/month*
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f8&disc=y&vers=689&s=4056&p=5117
|
|
0
|
|
|
|
Reply
|
davidlcassell (5578)
|
4/4/2007 6:07:54 AM
|
|
|
3 Replies
27 Views
(page loaded in 0.094 seconds)
|
|
|
|
|
|
|
|
|