@normanbg wrote:
Yes, I did want to reference the variable by its order in the data vector. Your solution (VAR1 VAR2 ... VAR20) is more or less what the workaround (mentioned in an earlier reply) did, but I was looking for what I thought would be a more elegant solution (one-line, without having to recast the Excel file). I guess there just isn't one.
Thank you for your reply.
You still haven't provided an actual use case. You should find that most actual calculations you need to do not involve needing to know either the order of the observations or of the variables.
Excel is a tool for working with SPREADSHEETs. In a spreadsheet you can easily reference any cell or even put any type of data into any cell. Structures that might work well for displaying information to users in spreadsheets are probably not going to work very well for doing data analysis.
@normanbg wrote:
Perhaps SAS sees the world differently, as you are implying, in which case I didn't find the solution because there isn't any—other than to restructure my Excel file, which was my workaround.
Of course there is a way to do this in SAS. There are many ways. I showed one such way.
If you want x to be a number:
x = input(scan(V, 3), best.);
Try SAS/IML and calling @Rick_SAS
Your usage of "vector" points to matrix operations (in SAS parlance), for which IML is the right tool. But it seems you only want to preserve a single value out of a series of values (contained in a series of observations).
Forget about the concepts of "vector" and "scalar". Explain what is the actual business problem you are trying to solve and perhaps we can translate into SAS code for you.
It sounds like you are saying you have this dataset.
data have;
id+1;
input v @@;
cards;
2 4 6 8 10
;
Obs id v 1 1 2 2 2 4 3 3 6 4 4 8 5 5 10
So if you want the value of the variable V for the observation where the variable ID has a value of 3 you could do:
proc print data=have;
where id=3;
var v;
run;
If you explain a more realistic business problem we could show more realistic code.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.