BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

Can someone help me understand the below line which has vname funcion?

 

FISC_YEAR = put(input(substr(vname(x),find(vname(x),"_",-length(vname(x)))+2),2.),z2.);
7 REPLIES 7
PaigeMiller
Diamond | Level 26

I think someone has found a very difficult way to do something very simple. But it seems as if you have changed the actual variable name to X, which doesn't really help. What was the actual variable name?

 

David, you need to run this code and see what value of FISC_YEAR results and what the value of X was. You can add PUT statements into your data step code, or just examine the output data set.

--
Paige Miller
Kurt_Bremser
Super User

This would make some sense if x was in fact a reference to an array (not a single variable) and the code was part of a DO OVER block.

 

Posting single statements out of context is usually very un-helpful.

MarkusWeick
Barite | Level 11

Hi @David_Billa,

following the reply of @Kurt_Bremser, I would assume that the variable names in the array are of the form "%%%%_YY" with the "YY" being the last two digits of the year. Your function than extracts the YY as a numeric with showing an eventual leading "0" in the format z2.

Best

Markus

Please keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
FreelanceReinh
Jade | Level 19

@MarkusWeick wrote:

I would assume that the variable names in the array are of the form "%%%%_YY" with the "YY" being the last two digits of the year.


I would expect one additional character between the last underscore and "YY" because otherwise the INPUT function would start to read at the second digit of the year ("YY").

MarkusWeick
Barite | Level 11
I think you are right. I didn't count carefully enough.
Please keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
mkeintz
PROC Star

@MarkusWeick wrote:

Hi @David_Billa,

following the reply of @Kurt_Bremser, I would assume that the variable names in the array are of the form "%%%%_YY" with the "YY" being the last two digits of the year. Your function than extracts the YY as a numeric with showing an eventual leading "0" in the format z2.

Best

Markus

Even so, and even if the offset were corrected, this is an ugly way to get the fiscal year.  SCAN for the last (i.e. "-1") word separated by '_'  would be much easier:

 


DATA _NULL_;
   ARRAY X {*} assets_74  assets_75  assets_76 (3*0);
   DO i=1 to 3;
     FISC_YEAR=INPUT(SCAN(VNAME(X{i}),-1,'_'),2.);
     put i= x{i}= fisc_year=;
   end;
run;

 

Of course, if the FISC_YEAR calculation is inside a loop, then other within-loop work better be done, because FISC_YEAR will keep only the last value.

 

The problem statement definitely needs context.


 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 7 replies
  • 759 views
  • 7 likes
  • 6 in conversation