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?
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;
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;
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:
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.