BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arodriguez
Lapis Lazuli | Level 10

Hi everyone,

I was wondering if there is any way to conserve the left blancs with SQL. See the following example

data tmp;

cat="First level  ";

output;

cat=" Second level";

output;

cat="  Third level";

output;

;

run;

proc sql noprint;

  select distinct cat into :var_levels separated by "#"

  from tmp;

quit;

%put &var_levels;

I obtain this output

Third level#Second level#First level

and I like to have

Third level# Second level#  First level.

1 ACCEPTED SOLUTION

Accepted Solutions
EricHoogenboom
Fluorite | Level 6

From the doc 🙂

notrim

separated by "#" notrim

Hth,

Eric

View solution in original post

3 REPLIES 3
EricHoogenboom
Fluorite | Level 6

From the doc 🙂

notrim

separated by "#" notrim

Hth,

Eric

arodriguez
Lapis Lazuli | Level 10

Thanks, like in almost everywhere the text is not trim I have not think about a possible option to do it

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

I think SQL will trim off the leading blanks by default, I don't know of a way to switch it off.  However you can easily fool it:

data tmp;

cat="First level  ";

output;

cat="_Second level";

output;

cat="__Third level";

output;

;

run;

proc sql noprint;

  select distinct cat into :var_levels separated by "#"

  from tmp;

quit;

%put %sysfunc(tranwrd(&var_levels,_, ));

Depends on what you want it for really.  If I am doing rtf output then I would put the rtf code in the variable.  Alternatively if you are creating a string from the 3 levels, then a retain, if last then output, should work.  Or you could tranpose them etc.

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
  • 3 replies
  • 957 views
  • 4 likes
  • 3 in conversation