BookmarkSubscribeRSS Feed
Garik
Obsidian | Level 7

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
7 REPLIES 7
PGStats
Opal | Level 21

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

PG
Garik
Obsidian | Level 7

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

 

thanks beforehand

 

PGStats
Opal | Level 21

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
Garik
Obsidian | Level 7

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;

Garik
Obsidian | Level 7

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

ballardw
Super User

@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.

 

Garik
Obsidian | Level 7

I just want to make look up using both the datasets

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 834 views
  • 0 likes
  • 3 in conversation