Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SAS datalines having spaces

Posted on 2010-11-09
3
Medium Priority
?
2,920 Views
Last Modified: 2013-11-16
Hi, I had a quick question about the possibility of adding spaces inside a datalines data. For,example in ‘DOMESTICAB’ I would like it to really be ‘DOMESTIC AB’. How can I make this happen?

data WORK.MYSECTION;
input @1 S41_T_CODE $10.
      @12 S41_M_CODE $4.
        @17 S41_TOTAL_NUM 2.
        @20 S41_TOTAL_AMT 2.
        @23 S41_AVG_AMT 2.;
DATALINES;
DOMESTICAB MCC1 10 20 30
DOMESTICBS MCC2 20 30 40
DOMESTICAB MCC3 50 60 70
INTERNATAB MCC1 80 90 10
INTERNATBS MCC4 11 22 33
        ;
run;
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
d507201 earned 1000 total points
ID: 34097425
You can't change the input data source but you can change what goes into the SAS data set.    Create a new variable and then give it the same name as the original.


data WORK.MYSECTION;
input @1 S41_T_CODE $10.
      @12 S41_M_CODE $4.
        @17 S41_TOTAL_NUM 2.
        @20 S41_TOTAL_AMT 2.
        @23 S41_AVG_AMT 2.;

      length new_s41_t_code $11;
      new_s41_t_code=catx(' ',substr(s41_t_code,1,8),substr(s41_t_code,9));

      drop s41_t_code;
      rename new_s41_t_code=s41_t_code;

DATALINES;
DOMESTICAB MCC1 10 20 30
DOMESTICBS MCC2 20 30 40
DOMESTICAB MCC3 50 60 70
INTERNATAB MCC1 80 90 10
INTERNATBS MCC4 11 22 33
        ;
run;

data _null_;  set mysection;
      put s41_t_code;
run;
0
 
LVL 11

Assisted Solution

by:theartfuldazzler
theartfuldazzler earned 1000 total points
ID: 34099434
Hi

You can change the normal delimiter of a space by setting an INFILE statement.  Below I have set my delimiter to be a pipe "|"

DATA Test;
infile datalines dlm='|' truncover;
informat x y z $20.;
INPUT x y z ;
datalines;
A B|B|C
;
RUN;
0
 

Author Comment

by:LuckyLucks
ID: 34105223
If I create the table as:
CREATE TBALE MYTABLE AS
Select T.Col1,
           T.Col2,
           T.Col3
from T;run;
quit;

And lets say the Col1 contains characters that have spaces in between, do I need to do the delimitor modification or SAS interprets that Col1 that contains spaced data is all one column?
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question