BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need to create a variable with some values containing leading values. 

output needed in dataset 'two'  for variable 'c'

c

all

  aaa

  bbb

  ddd

 

In the above output,  i need to have leading blanks for all except first value 'all'.     Please suggest. Thank you


data one; input a b$; datalines; 1 all 2 aaa 3 bbb 4 ddd ; data two; set one; if a=1 then c=a; else c= a; run;

 

 

3 REPLIES 3
heffo
Pyrite | Level 9

If you just want a leading space I would use the cat function. I would also use strip to make sure that there are no spaces to begin with in the variable a. 

data two;
set one;
if a=1 then c=a;
else c=  cat(" ",strip(a));
run;

Or am I missing something more?  

Reeza
Super User
What do you need the leading blanks for? PROC REPORT now has an indent option within the style or somewhere at least that can control indents.
Kurt_Bremser
Super User

Blanks in code are never blanks in data. Blanks in code are just separators between code elements. To have blanks as data, you need to make that clear to the data step compiler by using quotes and the proper concatenation operator:

a = "  " || a;

Note that this may cause the truncation of the values in a.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 510 views
  • 2 likes
  • 4 in conversation