View previous topic :: View next topic |
Author |
Message |
chandra_vssv Beginner
Joined: 08 May 2005 Posts: 26 Topics: 12 Location: pune
|
Posted: Mon Jun 08, 2009 3:06 am Post subject: SAS array help needed |
|
|
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 |
|
|
expat Intermediate
Joined: 01 Mar 2007 Posts: 475 Topics: 9 Location: Welsh Wales
|
Posted: Mon Jun 08, 2009 5:32 am Post subject: |
|
|
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 |
|
|
chandra_vssv Beginner
Joined: 08 May 2005 Posts: 26 Topics: 12 Location: pune
|
Posted: Mon Jun 08, 2009 9:22 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
expat Intermediate
Joined: 01 Mar 2007 Posts: 475 Topics: 9 Location: Welsh Wales
|
Posted: Tue Jun 09, 2009 12:43 am Post subject: |
|
|
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 |
|
|
chandra_vssv Beginner
Joined: 08 May 2005 Posts: 26 Topics: 12 Location: pune
|
Posted: Tue Jun 09, 2009 8:34 am Post subject: thanks |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue Jun 09, 2009 12:51 pm Post subject: Re: thanks |
|
|
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 |
|
|
chandra_vssv Beginner
Joined: 08 May 2005 Posts: 26 Topics: 12 Location: pune
|
Posted: Wed Jun 10, 2009 3:29 am Post subject: hi |
|
|
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 |
|
|
expat Intermediate
Joined: 01 Mar 2007 Posts: 475 Topics: 9 Location: Welsh Wales
|
Posted: Wed Jun 10, 2009 6:11 am Post subject: |
|
|
I've heard worse, believe me
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 |
|
|
chandra_vssv Beginner
Joined: 08 May 2005 Posts: 26 Topics: 12 Location: pune
|
Posted: Wed Jun 10, 2009 10:29 am Post subject: Hi |
|
|
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 |
|
|
|
|