BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
swayto
Fluorite | Level 6

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

134999080539119339870890467
295127378117965265761528244
317356133599925275651511349
480588797133768162105444197
581972419183144433793948864
6897675715983863910652914754
756384306364545714747312939
86062729076024411679315553
9118172680649676769487435333
1073432898133854964214964575
1 ACCEPTED SOLUTION

Accepted Solutions
supp
Pyrite | Level 9

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;

View solution in original post

4 REPLIES 4
Ksharp
Super User
data _null_;
 set sashelp.class;
 if age=14 then do;
  put 'Found age=14 at obs=' _n_;
 end;
run;
VENKATAMAHESH
Calcite | Level 5

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*/

supp
Pyrite | Level 9

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;
Astounding
PROC Star

Another approach if you just need to see the value:

 

proc print data=have (firstobs=6 obs=6);
   var var5;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 815 views
  • 5 likes
  • 5 in conversation