helen
2005-03-27 02:48:45 UTC
I can't believe I can't figure out how to do this. It seems so simple
to explain, so please bear with me.
I want to remove the first and last character from all the cells (all
variables, all observations) in my dataset. So in the end I want all
the variables to be 2 characters shorter, since they will be missing
both the first and the last character from the original variable. (I
want to do this so that I can ulimately compare DatasetA to DatasetB,
which should be the same except that all the cells in DatasetA are
currently enclosed in quotes whereas in DatasetB they are not. Of
course they are not exactly the same which is why I want to compare the
2 datasets to find the errors, but first I need to make sure I'm not
finding extraneous "errors" due to the extra first and last quotes! And
I don't just want to strip the quotes because some of the variables
have internal quotes I want to keep.)
I thought I wanted to use the substr function, but the 3rd argument is
not fixed--it varies depending on the length of the variable I'm
operating on. For each observation I have an array of about 70
variables I need to operate on. I think maybe I need a macro variable
to store the output of a length function but my facility with macro
variables, macro loops, etc. is weak and rusty so I gave up...but
perhaps there is a simple solution anyway.
A concrete example:
Original data:
ADDRESS CITY STATE
"1234 Main Street" "New York" "NY"
"5 Circle Ave" "San Francisco" "CA"
Desired data:
ADDRESS CITY STATE
1234 Main Street New York NY
5 Circle Ave San Francisco CA
Thanks,
Helen
to explain, so please bear with me.
I want to remove the first and last character from all the cells (all
variables, all observations) in my dataset. So in the end I want all
the variables to be 2 characters shorter, since they will be missing
both the first and the last character from the original variable. (I
want to do this so that I can ulimately compare DatasetA to DatasetB,
which should be the same except that all the cells in DatasetA are
currently enclosed in quotes whereas in DatasetB they are not. Of
course they are not exactly the same which is why I want to compare the
2 datasets to find the errors, but first I need to make sure I'm not
finding extraneous "errors" due to the extra first and last quotes! And
I don't just want to strip the quotes because some of the variables
have internal quotes I want to keep.)
I thought I wanted to use the substr function, but the 3rd argument is
not fixed--it varies depending on the length of the variable I'm
operating on. For each observation I have an array of about 70
variables I need to operate on. I think maybe I need a macro variable
to store the output of a length function but my facility with macro
variables, macro loops, etc. is weak and rusty so I gave up...but
perhaps there is a simple solution anyway.
A concrete example:
Original data:
ADDRESS CITY STATE
"1234 Main Street" "New York" "NY"
"5 Circle Ave" "San Francisco" "CA"
Desired data:
ADDRESS CITY STATE
1234 Main Street New York NY
5 Circle Ave San Francisco CA
Thanks,
Helen