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-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
  • 3 replies
  • 730 views
  • 0 likes
  • 4 in conversation