DATA Step, Macro, Functions and more

Using dash within an input

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Using dash within an input

Hi there

 

So I regularly use a piece of code that's a couple of thousand lines long. Every time I use it, I generally have to make a few small amendments to fit the current situation. I may have to change 10-15 small snippets of the code and I find it's easy to forget one or two. This can either result in wasted time by having to rerun the code or could actually allow errors in my output, so I'm trying to reduce the number of changes I have to make. One of the changes is the input part of the data step. This wasn't my code originally so feel free to not comment on the general structure too much! A whole load of variables are listed in the format section of the data step and then there is an input command similar to the below.

 

input A--F;

 

I often add new columns and I have to add this to about 5 data steps, which means I also have to change the input statement 5 times.

 

Is there a way I can say something like:

 

input A--EOF;


?

 

I know EOF doesn't work and I've tried googling for an answer with no success.

 

I could change the way the code is written in a more substantial way to reduce the burden but other people still use the code and have been using it for a long time, so I'd rather not mess with it too much if I don't need to.

 

Thanks in advance for any help.


Accepted Solutions
Solution
‎01-12-2016 07:12 AM
Super User
Super User
Posts: 7,942

Re: Using dash within an input

Posted in reply to Chris_Revill

Well, first off, why is the data structure changing.  It sounds like a broken import process.  Get import specification document built, agred, and programmed upon that.  Any change then incurs a full process change - which also helps as they will be less likely to change the data. 

 

As for you request, why not just put a macro variable in place:

%let cols=A--F;

 

data a;

  input &COLS.;

run;

data b;

  input &COLS.;

run;

...etc.

 

You would only have to change it once then.  Although if you fix the cause of the problem...

View solution in original post


All Replies
Solution
‎01-12-2016 07:12 AM
Super User
Super User
Posts: 7,942

Re: Using dash within an input

Posted in reply to Chris_Revill

Well, first off, why is the data structure changing.  It sounds like a broken import process.  Get import specification document built, agred, and programmed upon that.  Any change then incurs a full process change - which also helps as they will be less likely to change the data. 

 

As for you request, why not just put a macro variable in place:

%let cols=A--F;

 

data a;

  input &COLS.;

run;

data b;

  input &COLS.;

run;

...etc.

 

You would only have to change it once then.  Although if you fix the cause of the problem...

New Contributor
Posts: 3

Re: Using dash within an input

[ Edited ]

Thanks for your response. A little context may help you understand my situation. I'm a marketing analyst using SAS to process text files that have been output from a campaign management system. A lot of the segmenting is done in SAS and so when new requirements arise for the purposes of segmentation (almost a weekly occurrence at the moment) it often requires a new field to be created in the initial system and accommodated for in the SAS code.

 

The reason A--F is currently used is because a field is defined in the initial format statement that isn't an input and is populated later in the data step. I could probably make my life easier by simply moving this field to a later format statement and then I think I could replace "input A--F;" with "input;"? That is the solution is eluded to in my initial question. On reflection it's hardly a massive change for other users to accept and would be the most sensible. Another less pretty solution would be to make any new fields the second to last field in the output, rather than the last. Nowhere near as fool-proof though.

 

I'm relatively new to SAS so still learning and I appreciate your response.

 

Edited for SPAG.

Super User
Super User
Posts: 7,942

Re: Using dash within an input

Posted in reply to Chris_Revill

Sounds to me like the setup at the segmentation level wasn't done properly:

"A lot of the segmenting is done in SAS and so when new requirements arise for the purposes of segmentation (almost a weekly occurrence at the moment) it often requires a new field to be created in the initial system and accommodated for in the SAS code."

 

If a dataset is going to expand, normlise it (i.e. long rather than wide), so more rows appear rather than columns, or have an automated sql describe so processes further down the line don't need to consistently change.  Your left jumping at each change currently by the sounds of it.

New Contributor
Posts: 3

Re: Using dash within an input

You make a fair point. I'm working as a contractor though so I'm not about to start fundamentally changing all of their processes. Not to mention they're in the middle of a migration to a new system which should hopefully (from their perspective) eliminate the need for SAS altogether. In the meanwhile I am starting to get to a point where code changes won't be necessary on a weekly basis. The same segmentations are done regularly. In the past they always amended the code to cater only for the segmentation required that week. As and when each one comes up now, I'm adding it to the existing process. So eventually, weeks rather than months, no further amendments will be necessary. Thanks for the advice though. I may make use of it in future.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 207 views
  • 2 likes
  • 2 in conversation