BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yadaw
Fluorite | Level 6

I have two files with some data.

file1.txt

123

456

789

100

 

file2.txt

ABC

 

I want output file file3.txt as:-

123ABC

456ABC

789ABC

100ABC

 

How can i do this?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

one way

 

data file1;
input numVar;
datalines;
123
456
789
100
;

data file2;
charVar="ABC";
run;

proc sql;
	create table file3 as 
	select cats(numVar, charVar) as newVar
	from file1, file2;
quit;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

one way

 

data file1;
input numVar;
datalines;
123
456
789
100
;

data file2;
charVar="ABC";
run;

proc sql;
	create table file3 as 
	select cats(numVar, charVar) as newVar
	from file1, file2;
quit;
PeterClemmensen
Tourmaline | Level 20

Btw, do you want to output this as a TXT file?

 

And are file1 and file2 SAS data sets?

yadaw
Fluorite | Level 6
Output should be in file and file1 and file 2 are data sets
PeterClemmensen
Tourmaline | Level 20

You mean that your output should be in a TXT file?

yadaw
Fluorite | Level 6
No any file, doesn't matter text or any other.
PeterClemmensen
Tourmaline | Level 20

You can do something like this with a data step

 

data _null_;
	set file3;
	file "MyPath\MyFile.txt";
	put newVar;
run;

Or alternatively PROC EXPORT to export the file

Astounding
PROC Star

The INFILE  and FILE statements actually require complete paths, not just the file name itself:

 

data _null_;

infile "file2.txt";

input part2 $;

infile "file1.txt" end=done;

file "file3.txt" noprint;

do until (done);

   input part1 $;

   put part1 +(-1) part2;

end;

run;

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
  • 552 views
  • 3 likes
  • 3 in conversation