BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
claudiopcjr
Fluorite | Level 6

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:

 

claudiopcjr_1-1585844446198.png

 

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:

claudiopcjr_2-1585844534886.png

 

Does anyone know any change that I'd do on the code that I provided to reach the expected results ?

 

Thanks in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

 

 

 

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 2 replies
  • 418 views
  • 3 likes
  • 3 in conversation