BookmarkSubscribeRSS Feed
aarony
Obsidian | Level 7

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?

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

stat_sas
Ammonite | Level 13

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;

andreas_lds
Jade | Level 19

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 965 views
  • 0 likes
  • 4 in conversation