Hi everyone,
I'm creating a new column on a step DATA SET that I'm working on that intends to have the content of a column that already exists, but actually what SAS is making is to return the name of those columns that already exists. But to supply my needs in my proccess I need to make the SAS unsderstand that I really want are the contents. The image below show the result that I'm having:
Here's the code that I'm using:
DATA TABELA_HISTORICA_2;
SET TABELA_HISTORICA;
SEGM_PJ_P12M = "SEGM_PJ_"||PUT(YEAR(INTNX('MONTH',FECHAPER_STRT,12,'E')),z4.)||PUT(MONTH(INTNX('MONTH',FECHAPER_STRT,12,'E')),Z2.);
RUN;
And below are the results that I'm expecting to have:
Does anyone know any change that I'd do on the code that I provided to reach the expected results ?
Thanks in advance.
Use INTCK() function to calculate an index into an array.
DATA TABELA_HISTORICA_2;
SET TABELA_HISTORICA;
array _x segm_pj_200: ;
index=1+intck('month','01JAN2008'd,FECHAPER_STRT);
if 1 <= index <= dim(_x) then SEGM_PJ_P12M=_x(index);
RUN;
PUT creates character values and there is nothing there that references back to a variable.
I would try:
DATA TABELA_HISTORICA_2; SET TABELA_HISTORICA; SEGM_PJ_P12M = vvaluex(cats("SEGM_PJ_",PUT(iNTNX('MONTH',FECHAPER_STRT,12,'E'),yymmn6.),best12.)); run;
The VVALUEX function will actually return a CHARACTER variable with the formatted value of the variable that the name resolves to.
The format YYMMx does year and month number formats. The N says not to use a separator so the YYMMN6. format returns values like 200801 from the date. No need to create separate incremented dates, format pieces and then stick together.
Use INTCK() function to calculate an index into an array.
DATA TABELA_HISTORICA_2;
SET TABELA_HISTORICA;
array _x segm_pj_200: ;
index=1+intck('month','01JAN2008'd,FECHAPER_STRT);
if 1 <= index <= dim(_x) then SEGM_PJ_P12M=_x(index);
RUN;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.