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.);
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.
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.
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
@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 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.
And instead of using an array, I would transpose first and then extract the year from _NAME_..
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.