hi!! I able to read my text file using snipets in SAS university edition but struggling to modify the data.
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;
Wellcome to the forum 🙂
You have to be more specific than that, what is your exact problem?
Regards
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
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
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.
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;
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’;
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’;
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 .
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;
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?
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’;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.