DATA Step, Macro, Functions and more

how to create temorary array with two external files

Reply
Contributor
Posts: 39

how to create temorary array with two external files

the code I use is so

the code below does not work

 

 

libname myxlfl '/home/garikhgh0/my_data_set';

data mydata;
set myxlfl.main_file;
array myarray{1999:2005, 7} _temporary_;
if _N_ = 1 then
do year = 1999 to 2005;
do **bleep** = 1 to 7;
input myarray{year, **bleep**}@;
end;
end;
set myxlfl.second_file;
**bleep** = input(translate(code, '1234567', 'abcdefg'), 1.);
Level = myarray{year, **bleep**};
run;

 

main_file:

idyearSurnamecode
11999Garika
22000Aramb
32001Manuellac
42001Armined
52003Khanchalbeki
62004Baxtibekf
72004Gvidong

 

second_file:

abcdifg
23467907854
45786123213456
521435637162
11978327619
Respected Advisor
Posts: 4,920

Re: how to create temorary array with two external files

[ Edited ]

SET is for reading a SAS dataset, INPUT is for reading a text file. What is main_file?

PG
Contributor
Posts: 39

Re: how to create temorary array with two external files

understood, could you please show the syntax if you have two external files.

 

thanks beforehand

 

Respected Advisor
Posts: 4,920

Re: how to create temorary array with two external files

It should look like:

 

data mydata;
array myarray{1999:2005, 7} _temporary_;
if _N_ = 1 then do;
	infile "second_file.txt";
	do year = 1999 to 2005;
		do i = 1 to 7;
			input myarray{year, i} @;
			end;
		input;
	end;
	
infile "main_file.txt";
input id year surname :$12. code :$1.;
i = input(translate(code, '1234567', 'abcdefg'), best.);
Level = myarray{year, i};
run;
PG
Contributor
Posts: 39

Re: how to create temorary array with two external files

hello. it worked when I uploded the files as .txt as said.  

but it does not work when I upload the files as .xlsx

 


data o;

    infile '/home/garikhgh0/garik/name.xlsx';
      input id year surname :$12. code :$1.;
run;

Contributor
Posts: 39

Re: how to create temorary array with two external files

both the two files are datasets,  I have imorted them into sas.

Super User
Posts: 11,343

Re: how to create temorary array with two external files


Garik wrote:

the code I use is so

the code below does not work

 

 

libname myxlfl '/home/garikhgh0/my_data_set';

data mydata;
set myxlfl.main_file;
array myarray{1999:2005, 7} _temporary_;
if _N_ = 1 then
do year = 1999 to 2005;
do **bleep** = 1 to 7;
input myarray{year, **bleep**}@;
end;
end;
set myxlfl.second_file;
**bleep** = input(translate(code, '1234567', 'abcdefg'), 1.);
Level = myarray{year, **bleep**};
run;

 

main_file:

id year Surname code
1 1999 Garik a
2 2000 Aram b
3 2001 Manuella c
4 2001 Armine d
5 2003 Khanchalbek i
6 2004 Baxtibek f
7 2004 Gvidon g

 

second_file:

a b c d i f g
23 4 67 90 78 5 4
45 78 6 123 21 34 56
5 21 43 56 3 71 62
1 19 78 3 27 61 9

And what is the desired output?

 

How does it "not work"? Do you get errors? Show the code and error from the log in an code box.

No data? Show the code and messages from the log?

Undesired or unexpected data? Show the actual result and the desired output.

 

Contributor
Posts: 39

Re: how to create temorary array with two external files

I just want to make look up using both the datasets

Ask a Question
Discussion stats
  • 7 replies
  • 139 views
  • 0 likes
  • 3 in conversation