Please help me

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Please help me

Hello All,

Can you please help me in solving the query?

I have a dataset with 4 variables/column/fields.

I have field names-

Var1, Var2, MN_Var3  and Var4.

If Under   MN_Var3  I have--

              M

              N

              M

              M

              M

              N

              N

              M

              N

              M

              N

              M

              M

              N

i AM TRYING TO CREATE two new fields in the same table (without var4) with names- M_var5 and N_var6

M_var5 will have only 'M' from MN_var3 and N_var6 will have 'N' from MN_var3.

How can I do this using Proc sql in SAS.

Thank you.


Accepted Solutions
Solution
‎12-23-2013 08:30 PM
Trusted Advisor
Posts: 1,128

Re: Please help me

Please try,

proc sql;

  create table want as select *,

    case

      when mn_var3='M' then "M"

      else ''

    end

  as M_var5,

    case

      when mn_var3='N' then "N"

      else ''

    end

  as M_var6

    from have;

quit;

Thanks,

jag

Thanks,
Jag

View solution in original post


All Replies
Solution
‎12-23-2013 08:30 PM
Trusted Advisor
Posts: 1,128

Re: Please help me

Please try,

proc sql;

  create table want as select *,

    case

      when mn_var3='M' then "M"

      else ''

    end

  as M_var5,

    case

      when mn_var3='N' then "N"

      else ''

    end

  as M_var6

    from have;

quit;

Thanks,

jag

Thanks,
Jag
Contributor
Posts: 43

Re: Please help me

Thank you so much Jagdish,

I almost did it but I could not include else in it...

It helped me in all the ways...

Thank you

Dipu

Super User
Super User
Posts: 6,498

Re: Please help me

data want ;

  set have ;

  if MN_VAR3 = 'M' then M_VAR5=MN_VAR3;

  else if MN_VAR3 = 'N' then M_VAR6=MN_VAR3;

run;

Contributor
Posts: 43

Re: Please help me

Thank you very much Tom..:-)

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 214 views
  • 5 likes
  • 3 in conversation