Help using Base SAS procedures

for year, if then.

Reply
Frequent Contributor
Posts: 102

for year, if then.

I have an index from 1991-2013.

Because they are all over the place, I have manually looked into them to assign portfolios for them each year.

I have divided the pfo into 3 pfos each year and want to write a code for it but don’t know how to.

For example I want to write something like the below for 1991-2013.,

data f2; set f1;

pfo=.;

if pfoyr=1991, and index<-1.22 then pfo=1, -1.22=<index<=2.48 then pfo=2, and index >2.48 then pfo=3;

run;

Could you kindly let me know how to write such a code?

Super User
Super User
Posts: 7,975

Re: for year, if then.

Hi,

Perhaps you need an if/else construct:

data f2;

     set f1;

     pfo=.;

     if pfoyr=1991 and index < -1.22 then pfo=1;

     else if pfoyr=1991 and -1.22 <= index  <= 2.48 then pfo=2;

     else pfo=3;  /* Ommitted the code as all over 2.48 will come out here */

run;

Trusted Advisor
Posts: 1,228

Re: for year, if then.

Try something like this

data f2; set f1;

pfo=.;

if pfoyr=1991 and index<-1.22 then pfo=1;

else if -1.22=<index<=2.48 then pfo=2;

else if index >2.48 then pfo=3;

run;

Super Contributor
Posts: 345

Re: for year, if then.

The value of "pfo" depends on the variables pfoyr and index, right? So for different years, different index-values need to be checked.

If those assumptions are right, try this:

  • define an informat for each year
  • set pfo using that format

Example code:

proc format;

   invalue Index1991Fmt

      low -< -1.22 = 1

      -1.22 - 2.48 = 2

      2.48 <- high = 3

   ;

quit;

data f2;

     set f1;

     length pfo 8 FmtName $ 32;

     drop FmtName;

    

     FmtName = cats('Index', pfoyr, 'Fmt.');

     pfo = inputn(index,FmtName);

run;

Ask a Question
Discussion stats
  • 3 replies
  • 189 views
  • 0 likes
  • 4 in conversation