MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SAS array help needed

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
chandra_vssv
Beginner


Joined: 08 May 2005
Posts: 26
Topics: 12
Location: pune

PostPosted: Mon Jun 08, 2009 3:06 am    Post subject: SAS array help needed Reply with quote

Hi,

I have i/p dataset ' A 'with 5 columns and 22 rows, 4th column contains STATE Names. I want to load all these values from 'A' in to an array and match this 4th column with a field in another dataset 'B' at a particulat position say @44, if match found then i have to move all the values from 'A' to 'B'. B contains many records with same STATE.I have to write all the records of matching state. Very new to SAS. Please let me know how can i acheive this.

Lay out of 'A

Sno Name STATE AMNT
1 sam CA 10000
.
.
.
.
.
.
.
22 xyz NY 200000


Layout of B

50 fields and @44 position STATE column.

Thanks in advance
_________________
Regards,
Chandu
Back to top
View user's profile Send private message Yahoo Messenger
expat
Intermediate


Joined: 01 Mar 2007
Posts: 475
Topics: 9
Location: Welsh Wales

PostPosted: Mon Jun 08, 2009 5:32 am    Post subject: Reply with quote

MERGE dataset1 (in=id1) dataset2 (in=id2);
BY whatever;
_________________
If it's true that we are here to help others,
then what exactly are the others here for ?
Back to top
View user's profile Send private message
chandra_vssv
Beginner


Joined: 08 May 2005
Posts: 26
Topics: 12
Location: pune

PostPosted: Mon Jun 08, 2009 9:22 am    Post subject: Reply with quote

I got it by doing MERGE but i want the i/p 'A' dataset to be loaded in array, as per requirement. Please let me know how can i do that. Thanks in advance.
_________________
Regards,
Chandu
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Jun 08, 2009 10:42 am    Post subject: Reply with quote

chandra_vssv,

Check this link which explains array processing with examples

http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002299816.htm

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
expat
Intermediate


Joined: 01 Mar 2007
Posts: 475
Topics: 9
Location: Welsh Wales

PostPosted: Tue Jun 09, 2009 12:43 am    Post subject: Reply with quote

If you get the required results by an easier route, why the stupid requirement to use a more involved and difficult code route ?
_________________
If it's true that we are here to help others,
then what exactly are the others here for ?
Back to top
View user's profile Send private message
chandra_vssv
Beginner


Joined: 08 May 2005
Posts: 26
Topics: 12
Location: pune

PostPosted: Tue Jun 09, 2009 8:34 am    Post subject: thanks Reply with quote

Thanks Kolusu for the Link on Arrays, i am trying to understand the array concept in SAS, it is different in SAS from other programming languages(COBOL) .

Expat
Thanks for suggesstion as well. Cannot change the requirement.

Let me know incase if you can provide the solution. I understood one D arrays in SAS, i/p file is 2D. I have to match that 2D array element to a field in flat file.I am trying but running short of time.
_________________
Regards,
Chandu
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Tue Jun 09, 2009 12:51 pm    Post subject: Re: thanks Reply with quote

chandra_vssv wrote:
Thanks Kolusu for the Link on Arrays, i am trying to understand the array concept in SAS, it is different in SAS from other programming languages(COBOL) .


Chandra,

Huh? How is it different from COBOL? An array is an array irrespective of the language.

Secondly please don't show your attitude to people who are trying to help you. Expat raised a valid question as to why re-invent the wheel when there is a solution available for you. whoever is imposing the rules has no clue about programming.

By coding the program in something you have very little idea , you are just inviting trouble.

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
chandra_vssv
Beginner


Joined: 08 May 2005
Posts: 26
Topics: 12
Location: pune

PostPosted: Wed Jun 10, 2009 3:29 am    Post subject: hi Reply with quote

Kolusu,

I just started learning SAS, hardly 3-4 days. I conquer with Expat but i was just letting him know about my requirement. I do not mean it, i am sorry if something wrong in my previous reply.

You guys are really doing a wonderful job.
_________________
Regards,
Chandu
Back to top
View user's profile Send private message Yahoo Messenger
expat
Intermediate


Joined: 01 Mar 2007
Posts: 475
Topics: 9
Location: Welsh Wales

PostPosted: Wed Jun 10, 2009 6:11 am    Post subject: Reply with quote

I've heard worse, believe me Very Happy

Just more than a little confused ...................

If you load file A into an array, then try and merge it with file B, the variable name will have to be the same, so you create a new variable by Varname = Array_Name(n), or you also need to format file B into an array with the compare variable being referred to by the same index as that used for file A.
_________________
If it's true that we are here to help others,
then what exactly are the others here for ?
Back to top
View user's profile Send private message
chandra_vssv
Beginner


Joined: 08 May 2005
Posts: 26
Topics: 12
Location: pune

PostPosted: Wed Jun 10, 2009 10:29 am    Post subject: Hi Reply with quote

Expat

You are right , i tried in SAS editor , it is giving me results but not as expected. Here i have taken the data to be compared with array under cards but actual file is unknow, we dont know how many records will be processed (cant say , may be millions)
Code:

data TEST1;                                   
input @1 ssn $2.                             
      @4 st  $2.                             
;                                           
cards;                                       
10 CT                                       
20 CT
30 IL                                       
40 MI                                       
50 MI
;                                           
RUN;                                         
data TEST2(keep = ssn st st_Test2 stdes_Test2);
length j $2.                                 
       st_Test2 $2.                           
       stdes_Test2 $24.                       
;                                           
set Test1;                                   
array r1(22) $1 region1 - region22;         
array r2(22) $9 reg_des1-reg_des22;         
array r3(22) $1 div1 -div22;                 
array r4(22) $2 state1 - state22;       
array r5(22) $24 st_desc1 -st_desc22;   
J = 1;                                   
INFILE 'XYZ.dat(test2rgt)' ;
DO ;                                     
input r1(j) 1 - 1                       
      r2(j)3 - 11                       
      r3(j)13 - 13                       
      r4(j)15 - 16                       
      r5(j)18 - 41 ;                     
j = j + 1;                               
end;                                     
drop j;                                 
do i = 1 to 22;                         
if st = r4(i) then do;                   
st_Test2 = r4(i);                         
stdes_Test2 = r5(i);                     
end;                                     
end;                                     
run;                                     
proc print data = Test2;
run;                   

data in XYZ.dat(test2rgt) is

000001 N EAST      G CT CONNECTICUT 
000002 A MIDWEST   G IN INDIANA     
000003 A MIDWEST   Q IL ILLINOIS     
000004 A MIDWEST   M MI MICHIGAN     
000005 A MIDWEST   J OH OHIO         
000006 A MIDWEST   E WI WISCONSIN   
.
.
.
.
.
.
.
000022 B BELLSOUTH T TN TENNESSEE


EXpected output
Code:

10 CT  N EAST      G CONNECTICUT                                     
20 CT  N EAST      G CONNECTICUT
30 IL  A MIDWEST   Q ILLINOIS                                       
40 MI  A MIDWEST   M MICHIGAN                                     
50 MI  A MIDWEST   M MICHIGAN

_________________
Regards,
Chandu
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group