How to concatenate a value of data set to another data set

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to concatenate a value of data set to another data set

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?


Accepted Solutions
Solution
a month ago
PROC Star
Posts: 1,071

Re: How to concatenate a value of data set to another data set

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


All Replies
Solution
a month ago
PROC Star
Posts: 1,071

Re: How to concatenate a value of data set to another data set

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;
PROC Star
Posts: 1,071

Re: How to concatenate a value of data set to another data set

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

 

And are file1 and file2 SAS data sets?

Occasional Contributor
Posts: 5

Re: How to concatenate a value of data set to another data set

Output should be in file and file1 and file 2 are data sets
PROC Star
Posts: 1,071

Re: How to concatenate a value of data set to another data set

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

Occasional Contributor
Posts: 5

Re: How to concatenate a value of data set to another data set

No any file, doesn't matter text or any other.
PROC Star
Posts: 1,071

Re: How to concatenate a value of data set to another data set

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

Super User
Posts: 5,987

Re: How to concatenate a value of data set to another data set

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 142 views
  • 1 like
  • 3 in conversation