SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nilesh1985
Calcite | Level 5

Hi,

 

Environment : SAS ODAMID/ SAS Studio

 

I am trying to create a dataset using datalines, wherein one of the columns has leading spaces. I want to keep the leading spaces in the created dataset which is not happening by default.

Would appreciate any help. Thanks in advance.

Example 

data exp3;
infile datalines delimiter=",";
INPUT SNO :8. cat :$150.;
datalines;
1, main category
2, sub category
;
run;

Output (Default) 

1|main category
2|sub category

Desired Output
1|        main category
2|              sub category
 
Regards,
Nilesh
 
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

It's an informat thing. Use the $Charw. instead like this

 

data exp3;
infile datalines delimiter=","; 
INPUT SNO :8. cat :$char150.;
datalines;
1,     main category
2,         sub category
;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

It's an informat thing. Use the $Charw. instead like this

 

data exp3;
infile datalines delimiter=","; 
INPUT SNO :8. cat :$char150.;
datalines;
1,     main category
2,         sub category
;
run;
nilesh1985
Calcite | Level 5
On the same lines need some more clarification:-
data exp3;
infile datalines delimiter=",";
INPUT SNO :8. cat :$char150.;
datalines;
1, main category 1 - orthopedics
2, sub category
3, main category sub 2 - hemotology
4, sub category 2
;
run;

If I manually align the sub category to come below the - of main category it gets automatically aligned with less spacing, but if i put any other character like '*' in place of space, then it works.

Reason being i am trying to create a template for report.

Any help would be appreciated.

Regards,
Nilesh

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1113 views
  • 2 likes
  • 2 in conversation