SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Gluttony
Fluorite | Level 6

Hi everyone,

I have an imported dataset A and I need to get a specific cell value. Is there a way, like in other languages, to get the value by its coordinates (ex : A[4;5]) ?

Thank you

 

4 REPLIES 4
Tom
Super User Tom
Super User

@Gluttony wrote:

Hi everyone,

I have an imported dataset A and I need to get a specific cell value. Is there a way, like in other languages, to get the value by its coordinates (ex : A[4;5]) ?

Thank you

 


Why? Why would you want to do such a thing? How are you going to use the value once you have it?

 

If you want the value of a specific variable from a specific observation there are many ways.  

For example if the fifth column is named VAR5 then you could get the value for it from the fourth observation using this data step.

data want;
   set have (keep=VAR5 firstobs=4 obs=4);
run;
Gluttony
Fluorite | Level 6

Thank you for your answer,

I'm creating a function with proc fcmp to apply it on (let's say ages : 70, 71, 72, 73...), and in this function, I need to get the value associated to the age (70 for ex.) in table A and then use it with a multiplication

smantha
Lapis Lazuli | Level 10

To reference a particular value in a sas dataset column can do 

 

The conditional check itself will return a boolean value of 0 or 1. If using in a function you can use it as 70*(age=70); when age=70 the multiplication returns a 70 it will return 0 otherwise. Hope this helps.

 

if <colname> = value;

 

Tom
Super User Tom
Super User

Is this the one where you wanted to call a macro and run some other code to get a value the function can return?

So it looks like you want to pass in three values to your macro.  The NAME of the variable to sum and the upper and lower limits for the value of ID variable to include in the sum.

So an SQL query like this could be used to get the sum into the macro variable RESULT.

proc sql noprint;
select sum(&varname) format=best32. into :result  trimmed
from MYTABLE
where ID between &LOWER and &UPPER
;
quit;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 4 replies
  • 9599 views
  • 0 likes
  • 3 in conversation