BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

I am really not doing this right. I have this code

proc sql;

update table

set ((desc = n/a if cd is null) and (cd = 0 if desc = n/a) and

(desc = minor if cd = 1) and (desc = moderate if cd =2) and

(desc = major if cd = 3) and (desc = extreme if cd = 4));

run;

I think my code is just not right

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Try this:

proc sql;

update table yourtablename

set desc=

          case

               when cd is null

then 'n/a'

                when cd=1

then 'minor'

when cd=2

then 'moderate'

when cd=3

then 'major'

when cd=4

then 'extreme'

else 'others'

end;

update table want

  set cd=0 where desc='n/a';

quit;

View solution in original post

7 REPLIES 7
Haikuo
Onyx | Level 15

Try this:

proc sql;

update table yourtablename

set desc=

          case

               when cd is null

then 'n/a'

                when cd=1

then 'minor'

when cd=2

then 'moderate'

when cd=3

then 'major'

when cd=4

then 'extreme'

else 'others'

end;

update table want

  set cd=0 where desc='n/a';

quit;

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

I get errors saying: expressions using equals (=) has components that are different data types

Haikuo
Onyx | Level 15

You need to let us know the variable type of your variables: cd and desc. is 'cd' numeric?

You find the info by running:

1. proc sql;

describe table yourtablename;

quit;

or

2. proc contents data=your tablename;

run;

After knowing the types of your variables, you will be able to make changes.

Regards,

Haikuo

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

They are both text fields

Haikuo
Onyx | Level 15

Well, then:

proc sql;

update table yourtablename

set desc=

           case

                when cd is null

  then 'n/a'

                 when strip(cd)='1'

  then 'minor'

  when strip(cd)='2'

  then 'moderate'

  when strip(cd)='3'

  then 'major'

  when strip(cd)='4'

  then 'extreme'

  else 'others'

  end;

  update table want

   set cd='0' where desc='n/a';

quit;

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

I got it to work by putting ' ' around the 0-4 and it worked

Haikuo
Onyx | Level 15

There you go!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 876 views
  • 0 likes
  • 2 in conversation