Help using Base SAS procedures

Is there any more clever way to do it?

Frequent Contributor
Posts: 131

Is there any more clever way to do it?

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.

VALUE valuefmt
17-<20 ...
21-25 ...

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

DATA work.check;
SET work.test;
DROP a b;
RENAME a2=a b2=b;
RUN; Message was edited by: bncoxuk
Posts: 9,370

Re: Is there any more clever way to do it?

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:毙

Occasional Contributor
Posts: 5

Re: Is there any more clever way to do it?

DATA work.check;
SET work.test;
FORMAT a valuefmt.;
FORMAT b valuefmt.;
Occasional Contributor
Posts: 13

Re: Is there any more clever way to do it?

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.
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Is there any more clever way to do it?

Posted in reply to Kevin_Graduate
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?
Regular Contributor
Posts: 241

Re: Is there any more clever way to do it?

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

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

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

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

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

    1     4    4
    2     4    5

Ask a Question
Discussion stats
  • 5 replies
  • 6 in conversation