Hello everyone. I am trying to write code to a txt file, and in doing some I ran into an interesting question.
How do you write a vairable from a dataset to a file, concatenate with a string WITHOUT a space occuring between them?
Example, if you had the following code.
data person;
infile datalines delimiter=',' dsd missover;
informat TESTA $300.;
input TestA;
datalines;
Testthis
one
one
ONe1
twoone
heyman
;
filename codeTest 'C:\urdesktop\codecreation.txt' ;
/*could use a data _null_ step here*/
data Testhutto;
set person;
file codeTest lrecl=20000 ;
put TestA'heyman';
run;
It would give you a text file that has the variable, folowed by a space, and then the string 'heyman'.
SO you would get.
Testthis heyman
one heyman
...
What I WANT is
TestthisHeyman
oneHeyman
...
I do not want the space (as the code has no space in it). Does anyone know the option to get around this?
Thanks!
Brandon
Pointer control.
put TestA +(-1) 'heyman';
When you use LIST-PUT as you have here SAS adds a space after the last value. You just need to back up.
Pointer control.
put TestA +(-1) 'heyman';
When you use LIST-PUT as you have here SAS adds a space after the last value. You just need to back up.
+(-1) between the variables.
data Testhutto;
set person;
file codeTest lrecl=20000 ;
put TestA +(-1) 'heyman';
run;
Oh that's awesome! Thanks very much I will apply that across the places I want the varialbes!
This is exactly what I was looking for, thanks to both of your for your help!
Hi,
You could try "+(-1)":
data _null_;
a='Hello';
put a "world";
put a +(-1) "world";
run;
giving:
Hello world
Helloworld
"+(-1)" tells the output pointer to go back one position.
Regards,
Amir.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.