BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
normanbg
Obsidian | Level 7
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.
Tom
Super User Tom
Super User

@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.

 

 

Reeza
Super User
SAS doesn't really have concepts such as vectors, arrays or matrices within the data processing side, except within IML. Otherwise, it has data sets and macro variables that will persist between procs. This does mean you have to re-think how some things are done compared to other languages that are more matrix/vector/scalar based. And the terminology is of course different as well. If you're transitioning to SAS, it would be better to describe your business or base problem to help find the optimal solution otherwise you're very often going to be doing things inefficiently or running into the xy problem.
https://en.wikipedia.org/wiki/XY_problem
normanbg
Obsidian | Level 7
I don't think so. I designed a simple workaround and completed the project, but my inability to extract a value from a list (call it what you like) when I know its row and column coordinates, bothered me enough to pursue. 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.
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
PGStats
Opal | Level 21

If you want x to be a number:

 

x = input(scan(V, 3), best.);

PG
normanbg
Obsidian | Level 7
Great, just a single line. Can't see where I could go wrong. But I did. When I tried it, and then printed V and x, I got the 5 correct entries for V and 5 blanks for x.
Ksharp
Super User

Try SAS/IML and calling @Rick_SAS 

normanbg
Obsidian | Level 7
Why should that be necessary?
Kurt_Bremser
Super User

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).

Tom
Super User Tom
Super User

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.

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 25 replies
  • 4517 views
  • 3 likes
  • 7 in conversation