Question. How do I find a value of variable Var5 in observation 6,using code?
Obs var1 var2 var3 var4 var5 var6 var7 var8 var9 var10
1 | 349 | 990 | 805 | 391 | 193 | 39 | 870 | 890 | 467 |
2 | 951 | 273 | 781 | 17 | 965 | 265 | 761 | 528 | 244 |
3 | 173 | 561 | 335 | 999 | 25 | 275 | 651 | 511 | 349 |
4 | 80 | 588 | 797 | 133 | 768 | 162 | 105 | 444 | 197 |
5 | 819 | 724 | 191 | 831 | 444 | 337 | 93 | 948 | 864 |
6 | 897 | 675 | 715 | 983 | 863 | 910 | 652 | 914 | 754 |
7 | 56 | 384 | 306 | 364 | 545 | 714 | 747 | 312 | 939 |
8 | 606 | 272 | 907 | 602 | 44 | 116 | 793 | 155 | 53 |
9 | 118 | 172 | 680 | 649 | 676 | 769 | 487 | 435 | 333 |
10 | 734 | 328 | 981 | 338 | 549 | 642 | 149 | 64 | 575 |
Is this what you are looking to do?
data have;
infile datalines missover;
input
var1 var2 var3 var4 var5
var6 var7 var8 var9;
datalines;
349 990 805 391 193 39 870 890 467
951 273 781 17 965 265 761 528 244
173 561 335 999 25 275 651 511 349
80 588 797 133 768 162 105 444 197
819 724 191 831 444 337 93 948 864
897 675 715 983 863 910 652 914 754
56 384 306 364 545 714 747 312 939
606 272 907 602 44 116 793 155 53
118 172 680 649 676 769 487 435 333
734 328 981 338 549 642 149 64 575
;
run;
data want(keep=var5);
set have;
if _n_ = 6 then output;
run;
data _null_;
set sashelp.class;
if age=14 then do;
put 'Found age=14 at obs=' _n_;
end;
run;
data sample;
input a b c d e;
lines;
1 4 3 5 6
1 5 7 4 2
1 2 8 1 5
1 0 5 3 2
1 2 2 3 2
6 2 5 6 9
;
run;
%macro val(row,col);
data search(keep=value);
set sample;
array val {*} _NUMERIC_;
value = val{&col};
if _N_ = &row;
%mend;
%val(4,3);/*Call it*/
Is this what you are looking to do?
data have;
infile datalines missover;
input
var1 var2 var3 var4 var5
var6 var7 var8 var9;
datalines;
349 990 805 391 193 39 870 890 467
951 273 781 17 965 265 761 528 244
173 561 335 999 25 275 651 511 349
80 588 797 133 768 162 105 444 197
819 724 191 831 444 337 93 948 864
897 675 715 983 863 910 652 914 754
56 384 306 364 545 714 747 312 939
606 272 907 602 44 116 793 155 53
118 172 680 649 676 769 487 435 333
734 328 981 338 549 642 149 64 575
;
run;
data want(keep=var5);
set have;
if _n_ = 6 then output;
run;
Another approach if you just need to see the value:
proc print data=have (firstobs=6 obs=6);
var var5;
run;
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 16. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.