BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Feddy
Obsidian | Level 7

hi!! I able to read my text file using snipets in SAS university edition but struggling to modify the data.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You could save a lot of time if you had post your log and your output.

I'm using too SAS UE and this is not an issue.

 

Relating to your code:

PROC IMPORT DATAFILE="/folders/myshortcuts/My_Folders/New Text Document.txt"
OUT=WORK.Cont;
DBMS=txt;
REPLACE
RUN;

each row is imported as one observation without parsing the data into variables.

that is because you have no delimiters between the variables.

you can't use space as delimiter unless you want first name and last name separated.

that's why I asked:

How would you distinct between first name and last name in case of name contains 3 strings ?

Now relating to your first trial code:

DATA contest;
INFILE ’/folders/myshortcuts/My_Folders/New Text Document’;
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Score1 Score2 Score3 Score4 Score5) (4.1);
RUN;
PROC PRINT DATA = contest;
TITLE ’Pumpkin Carving Contest’;

when I run it I got 3 rows only.

to overcome it you need add TRUNCOVER option to the INFILE statement:

    

INFILE ’/folders/myshortcuts/My_Folders/New Text Document’ truncover;

another issue - in case the name is shorter then 16 characters, the age come to be part of the name.

check the log - there are notes starting: Invalid data for ... 

once again, that is because data miss delimiters between variables.

 

My solution:

enter commas between the variables, define delimiter=',' in the infile and add truncover option,

as in:

data my_data;
length name $16 datex $10; infile datalines dlm=',' truncover ; input Name $ age $ type $ datex $ score1-score5 4.1 ;
date = input(datex, mmddyy10.); drop datex; format date mmddyy10.; datalines; Alicia Grossman, 13, c, 10-28-2008, 7.8, 6.5, 7.2, 8.0, 7.9 Matthew Lee, 9, D, 10-30-2008, 6.5, 5.9, 6.8, 6.0, 8.1 Elizabeth Garcia, 10, C, 10-29-2008, 8.9, 7.9, 8.5, 9.0, 8.8 Lori Newcombe, 6, D, 10-30-2008, 6.7, 5.6, 4.9, 5.2, 6.1 Jose Martinez, 7, d, 10-31-2008, 8.9, 9.5, 10.0, 9.7, 9.0 Brian Williams, 11, C, 10-29-2008, 7.8, 8.4, 8.5, 7.9, 8.0 ; run;

View solution in original post

20 REPLIES 20
PeterClemmensen
Tourmaline | Level 20

Wellcome to the forum 🙂

 

You have to be more specific than that, what is your exact problem?

 

Regards

Feddy
Obsidian | Level 7

Hi,its simple i have my raw data in my folder and i print it easily but i want in a formatted way. How i import raw data and make some modification like read it as formatted way.      

Example:

Alicia Grossman 13 c 10-28-2008 7.8 6.5 7.2 8.0 7.9
Matthew Lee 9 D 10-30-2008 6.5 5.9 6.8 6.0 8.1
Elizabeth Garcia 10 C 10-29-2008 8.9 7.9 8.5 9.0 8.8
Lori Newcombe 6 D 10-30-2008 6.7 5.6 4.9 5.2 6.1
Jose Martinez 7 d 10-31-2008 8.9 9.510.0 9.7 9.0
Brian Williams 11 C 10-29-2008 7.8 8.4 8.5 7.9 8.0

Above data in a formatted way.

I am using sas university version 9.2 

 

 

Feddy
Obsidian | Level 7

Data:

Alicia Grossman 13 c 10-28-2008 7.8 6.5 7.2 8.0 7.9
Matthew Lee 9 D 10-30-2008 6.5 5.9 6.8 6.0 8.1
Elizabeth Garcia 10 C 10-29-2008 8.9 7.9 8.5 9.0 8.8
Lori Newcombe 6 D 10-30-2008 6.7 5.6 4.9 5.2 6.1.
Jose Martinez 7 d 10-31-2008 8.9 9.510.0 9.7 9.0
Brian Williams 11 C 10-29-2008 7.8 8.4 8.5 7.9 8.0

 

I able to print the above data but i wanted in a formated way.Please help me out

I am using SAS university version 

Shmuel
Garnet | Level 18

Please post:

1) your code to read the text file. Did you save it as sas dataset :

2) your code trying to modify the dadset ? the text file ? 

    and the log of running this code. 

    describe what modification you want to do.

Shmuel
Garnet | Level 18

How would you distinct between first name and last name in case of name contains 3 strings ?

You better have a delimiter between the variables like comma or other character.

You want it formated - give an example.

 

data my_data;

        infile datalines;

        input  FName $ LName $ var1 $ date_x mmffyy10. var3 var4 var5 var6 best 4.1;

       format date_x  date9.;

datalines;

Alicia Grossman 13 c 10-28-2008 7.8 6.5 7.2 8.0 7.9
Matthew Lee 9 D 10-30-2008 6.5 5.9 6.8 6.0 8.1
Elizabeth Garcia 10 C 10-29-2008 8.9 7.9 8.5 9.0 8.8
Lori Newcombe 6 D 10-30-2008 6.7 5.6 4.9 5.2 6.1
Jose Martinez 7 d 10-31-2008 8.9 9.510.0 9.7 9.0
Brian Williams 11 C 10-29-2008 7.8 8.4 8.5 7.9 8.0

;

run;

Feddy
Obsidian | Level 7

Issue is i am not able to import the file. I cleared with how to import the file using snippet but i need a formatted output which is in any format.

DATA contest;
INFILE ’/folders/myshortcuts/My_Folders/New Text Document’;
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Score1 Score2 Score3 Score4 Score5) (4.1);
RUN;
PROC PRINT DATA = contest;
TITLE ’Pumpkin Carving Contest’;

Feddy
Obsidian | Level 7

Issue is i am not able to import the file. I cleared with how to import the file using snippet but i need a formatted output which is in any format.

DATA contest;
INFILE ’/folders/myshortcuts/My_Folders/New Text Document’;
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Score1 Score2 Score3 Score4 Score5) (4.1);
RUN;
PROC PRINT DATA = contest;
TITLE ’Pumpkin Carving Contest’;

Feddy
Obsidian | Level 7
i am confusing you ??
Feddy
Obsidian | Level 7
im using sas university version
Shmuel
Garnet | Level 18

Assuming data contest satifies you, you can print it by:

 

proc print data=contest noobs;

  var name age type date score1-score5;

  format name $16. age 2. type $1. date mmddyy10. score1-scror5 4.1;

run;

 

that will give you a formated report .

Feddy
Obsidian | Level 7
/** Import an Txt file. **/
PROC IMPORT DATAFILE="/folders/myshortcuts/My_Folders/New Text Document.txt"
OUT=WORK.Cont;
DBMS=txt;
REPLACE
RUN;

/** Print the results**/

PROC PRINT DATA=work.Cont;
RUN;
this is my import txt snippet where i can write the program??
Shmuel
Garnet | Level 18

You could save a lot of time if you had post your log and your output.

I'm using too SAS UE and this is not an issue.

 

Relating to your code:

PROC IMPORT DATAFILE="/folders/myshortcuts/My_Folders/New Text Document.txt"
OUT=WORK.Cont;
DBMS=txt;
REPLACE
RUN;

each row is imported as one observation without parsing the data into variables.

that is because you have no delimiters between the variables.

you can't use space as delimiter unless you want first name and last name separated.

that's why I asked:

How would you distinct between first name and last name in case of name contains 3 strings ?

Now relating to your first trial code:

DATA contest;
INFILE ’/folders/myshortcuts/My_Folders/New Text Document’;
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Score1 Score2 Score3 Score4 Score5) (4.1);
RUN;
PROC PRINT DATA = contest;
TITLE ’Pumpkin Carving Contest’;

when I run it I got 3 rows only.

to overcome it you need add TRUNCOVER option to the INFILE statement:

    

INFILE ’/folders/myshortcuts/My_Folders/New Text Document’ truncover;

another issue - in case the name is shorter then 16 characters, the age come to be part of the name.

check the log - there are notes starting: Invalid data for ... 

once again, that is because data miss delimiters between variables.

 

My solution:

enter commas between the variables, define delimiter=',' in the infile and add truncover option,

as in:

data my_data;
length name $16 datex $10; infile datalines dlm=',' truncover ; input Name $ age $ type $ datex $ score1-score5 4.1 ;
date = input(datex, mmddyy10.); drop datex; format date mmddyy10.; datalines; Alicia Grossman, 13, c, 10-28-2008, 7.8, 6.5, 7.2, 8.0, 7.9 Matthew Lee, 9, D, 10-30-2008, 6.5, 5.9, 6.8, 6.0, 8.1 Elizabeth Garcia, 10, C, 10-29-2008, 8.9, 7.9, 8.5, 9.0, 8.8 Lori Newcombe, 6, D, 10-30-2008, 6.7, 5.6, 4.9, 5.2, 6.1 Jose Martinez, 7, d, 10-31-2008, 8.9, 9.5, 10.0, 9.7, 9.0 Brian Williams, 11, C, 10-29-2008, 7.8, 8.4, 8.5, 7.9, 8.0 ; run;
Reeza
Super User

There are SAS tutorials here:

http://support.sas.com/training/tutorial/

 

In your particular case, you probably want to create a SAS program and then work off that. It sounds like you may be working in the Visual Programmer side?

 

 

Feddy
Obsidian | Level 7

Sir,

I not yet get the output.If there any problem in my code or the path is wrong  

DATA contest;
INFILE ’/folders/myshortcuts/My_Folders/New.txt’ truncover;
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Score1 Score2 Score3 Score4 Score5) (4.1);
RUN;
PROC PRINT DATA = contest;
TITLE ’Pumpkin Carving Contest’;

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