Hi,
I need to read all values of some columns of a dataset, managed them adding some fixed string and finally put them the result string in a variable.
Here you are the code:
%let bodymsgstring = '';
data outds;
set WORK.inputds end=EOF;
length tmpbodymsgstring $10000;
retain tmpbodymsgstring '';
tmpbodymsgstring = tmpbodymsgstring || col1 || trim(left(col2)) || "\n";
if EOF then do;
call symput('bodymsgstring', tmpbodymsgstring);
end;
run;
%put bodymsgstring= &bodymsgstring;
The result string at the end of the elaboration is empty. Could someone explain me why?
Many thanks
Hi Garag..
Lets try with this code....(Not tested)...
%let bodymsgstring = '';
data outds;
length tmpbodymsgstring $10000;
set WORK.inputds end=EOF;
retain tmpbodymsgstring '';
tmpbodymsgstring_1 = tmpbodymsgstring || col1 || trim(left(col2)) || "\n";
if EOF then do;
call symput('bodymsgstring', tmpbodymsgstring_1);
end;
drop tmpbodymsgstring;
rename tmpbodymsgstring_1=tmpbodymsgstring;
run;
%put bodymsgstring= &bodymsgstring;
Regards..
Sanjeev.K
You need to TRIM TMPBODYMSGSTRING
tmpbodymsgstring = Trim(tmpbodymsgstring) || col1 || trim(left(col2)) || "\n";
You may also need to trim(col1) to get the desired result.
Hi data_null_..
It is working fine with trim function..
Can you please explain why is is not working without trim function???
Regards..
Sanjeev.K
Without the outer TRIM function, the second set of characters are appended to the end of the 10,000 characters of the first (most of which are blank). The TRIM removes the trailing blanks and allows you to append the values of the next record to immediately follow the '/n' of the preceding record.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.