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 |
SET is for reading a SAS dataset, INPUT is for reading a text file. What is main_file?
understood, could you please show the syntax if you have two external files.
thanks beforehand
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;
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;
both the two files are datasets, I have imorted them into sas.
@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.
I just want to make look up using both the datasets
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 25. Read more here about why you should contribute and what is in it for you!
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.