BookmarkSubscribeRSS Feed
bncoxuk
Obsidian | Level 7
I first created a format and applied it to the existing variables a, b. But this method using put statement is not very neat with DROP, RENAME etc. Is there any clever way to do this without assigning to new variables? Thanks for advice.

PROC FORMAT;
VALUE valuefmt
17-<20 ...
21-25 ...
...

DATA work.test;
a=18; b=19;output;
a=15; b=24;output;
run;

DATA work.check;
SET work.test;
a2=PUT(a,valuefmt.);
b2=PUT(b,valuefmt.);
DROP a b;
RENAME a2=a b2=b;
RUN; Message was edited by: bncoxuk
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
When you use < or > signs in your code, the forum posting mechanism mistakenly thinks you are passing HTML tags to your post. This behavior can cause posts to appear truncated.

The workaround is to "protect" your < and > signs in code by using search and replace to replace any < symbols with &lt; and replace any > symbols with &gt; in the code, as explained in the previous forum posting:
http://support.sas.com/forums/thread.jspa?messageID=27609毙

cynthia
zilok
Calcite | Level 5
DATA work.check;
SET work.test;
FORMAT a valuefmt.;
FORMAT b valuefmt.;
RUN;
Kevin_Graduate
Calcite | Level 5
The format is not useful. Basically it won't change the type of the variable. So, as a and b are numeric values, their formated values using FORMAT are still numeric. This does not make sens if the PROC FORMAT sets the format to characters.
DF
Fluorite | Level 6 DF
Fluorite | Level 6
Formatting is entirely superficial - it doesn't change any of your values. It's useful because you can use it to group things up (e.g. proc tabulate, means etc. can group up based on your formatted output, without adding new fields, or changing the original values).

What is it you're trying to do?
chang_y_chung_hotmail_com
Obsidian | Level 7

in case bncoxuk wanted to "recode" using a format:

   /* a test dataset */
   data one;
     a=18; b=19; output;
     a=15; b=24; output;
   run;

   /* recoding using a format */
   proc format;
      value level
       0-< 5 = 1
       5-<10 = 2
      10-<15 = 3
      15-<20 = 4
      20-<25 = 5
      other = .;
   run;

   /* recoding */
   data two;
      set one;
      a = input(put(a, level.), best.);
      b = input(put(b, level.), best.);
   run;

   /* check */
   proc print data=two;
   run;
   /* on lst
   Obs    a    b

    1     4    4
    2     4    5
   */

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
  • 5 replies
  • 803 views
  • 0 likes
  • 6 in conversation