- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody! I encountered a question in the input statement. I want to create a dataset with one variable and three observations. Each observation is a single digit.
The data step I wrote is the following:
data k;
input x 1. @@;
datalines;
123
;
run;
Those three digits are next to each other and I want them to lie in three observations. When I ran the data step, it gave a data set with 80 observations and one variable x. The first three observations are 1, 2 and 3. The rest of the observations are all missing value. You could run it if you like. Could you be so kind to tell me why it happened? It should be a dataset with variable x and three observations.
Thanks a lot!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS will pad the inline records ('CARDS') to 80 columns (actually a multiple of 80 if your text lines are longer than 80).
You could add a line to skip the missing values.
if x=. then delete;
Or you could use PARMCARDS instead of CARDS (datalines). In line data generated this way is not padded to card image length.
options parmcards=tempdata;
filename tempdata temp;
parmcards;
123
;
data k;
infile tempdata;
input x 1. @@;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Here is a small modification of your code that should give you 3 observations of 1 variable. I split the data into 3 lines and read it with a minor tweak..
data k;
input x:1.;
datalines;
1
2
3
;
run;Proc print;
Here is a print for your reference...
Obs x
1 1
2 2
3 3
Hope this helps.... Good Luck...!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for your time and attention! But the thing is that I cannot change the datalines. The datalines must remain unchanged as 123.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there a delimiter? and how long is the data?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you always know how many you are reading then @ instead of @@
data k;
do i=1 to 3;
input x 1. @;
output;
end;
drop i;
datalines;
123
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS will pad the inline records ('CARDS') to 80 columns (actually a multiple of 80 if your text lines are longer than 80).
You could add a line to skip the missing values.
if x=. then delete;
Or you could use PARMCARDS instead of CARDS (datalines). In line data generated this way is not padded to card image length.
options parmcards=tempdata;
filename tempdata temp;
parmcards;
123
;
data k;
infile tempdata;
input x 1. @@;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data k;
input x @@;
datalines;
1 2 3
;
run;
Much appreciate your attention and time!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
1. You have introduced a space between the individual records in this scenario. I guess it is read as a delimited data.
2. You have also removed the variable type definition of x.
Perhaps the gurus here may add to it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yeah. That, I think, should be the reason. Thank you for your help! Much appreicate your attention!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try this
data k;
input x1$;
do i = 1 to 3;
Dig1 = substr(x1,i,1);
output;
end;
drop i;
datalines;
123
456
675
;
run;
Proc Print data = k;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content