Reputation: 1
data macpro.bimodels_type;
infile datalines ;
input Model & $ model_class$ model_price model_frame$ DOpurchase;
*length Model$20. model_class$25. model_price4. ;
datalines;
Black Bora Track 796 Aluminum 01Aug2009
Delta Breeze Road 400 CroMoly 23Aug2010
Jet Stream Track 1160 CroMoly 01Aug2009
Mistral Road 1995 Carbon Comp 01Jul2010
Nor'easter Mountain 900 Aluminum 05Jul2010
Santa Ana Mountain 459 Aluminum 20Jul2010
Scirocco Mountain 2300 Titanium 08Sep2011
Trade Wind Road 759 Aluminum 08Sep2011
in Model
variable i where trying to fix blank, i used & syntax like input Model & $
and so on... but i can't able to fix Black Bora
in single column. how i can fix this.
Upvotes: 0
Views: 501
Reputation: 23
If you are indeed trying to wrap your code containing datalines inside a macro (as the title suggests), this won't work. Datalines/cards are statements that cannot be executed within a macro. As an alternative, you may save your datalines in a text file and read in that file, which works within macro code.
Upvotes: 1
Reputation: 51566
You cannot change the length of a character variable after SAS has already determined what it will be. I find it much easier to get it right if I explicitly define the variables before using them in other statements.
data bimodels_type;
infile datalines truncover ;
length Model $20 model_class $25 model_price 8 model_frame $20 DOpurchase 8 ;
format DOpurchase date9. ;
input Model & model_class model_price model_frame & DOpurchase :date.;
datalines;
Black Bora Track 796 Aluminum 01Aug2009
Delta Breeze Road 400 CroMoly 23Aug2010
Jet Stream Track 1160 CroMoly 01Aug2009
Mistral Road 1995 Carbon Comp 01Jul2010
Nor'easter Mountain 900 Aluminum 05Jul2010
Santa Ana Mountain 459 Aluminum 20Jul2010
Scirocco Mountain 2300 Titanium 08Sep2011
Trade Wind Road 759 Aluminum 08Sep2011
;
For the &
modifier to work you need to have at least two spaces (delimiters actually) after the value and before the next value. So in your data the fourth line is going to have a problem since there are not two spaces before the date.
You could either fix the input data.
Mistral Road 1995 Carbon Comp 01Jul2010
Or if you know that every record will have a date you could read it as part of the previous character variable and then take it back out.
data bimodels_type;
infile datalines truncover ;
length Model $20 model_class $25 model_price 8 model_frame $50 DOpurchase 8 ;
format DOpurchase date9. ;
input Model & model_class model_price model_frame $50.;
DOpurchase=input(scan(model_frame,-1,' '),date11.);
model_frame = substr(model_frame,1,length(model_frame)-9);
datalines;
Black Bora Track 796 Aluminum 01Aug2009
Delta Breeze Road 400 CroMoly 23Aug2010
Jet Stream Track 1160 CroMoly 01Aug2009
Mistral Road 1995 Carbon Comp 01Jul2010
Nor'easter Mountain 900 Aluminum 05Jul2010
Santa Ana Mountain 459 Aluminum 20Jul2010
Scirocco Mountain 2300 Titanium 08Sep2011
Trade Wind Road 759 Aluminum 08Sep2011
;
Upvotes: 1