BookmarkSubscribeRSS Feed
Rasheed
Calcite | Level 5

Sorry I didn't understand it

Patrick
Opal | Level 21
Rasheed
Calcite | Level 5

When I used cats instead catx the problem is even bigger this time now it removes all spaces and produced

data CCD_1; setCD_11CD_12CD_13CD_14CD_15CD_16CD_17CD_18CD_19CD_110; rename COL1=C;

                   -------------------------------------------------------------------------------------------------------------

Reeza
Super User

try the concatenate function.

Look at all the options available in the CAT_ family as well and decide which will work for you.

Patrick
Opal | Level 21

So then it looks as if you need a blank between the data set names. That's what CATX() would give you.

Not really sure why people are so hard on you. It looks like you're just taking peoples code, run it and if there is an error you just post the problem again without first spending some time doing some investigation and RTM on you own. But let's assume it's just a case of being confused and not being on the level yet to help yourself.

Looking at the problem you had when you used catx():  "data CCD_1; setCD_11 CD_12 CD_13 CD_14 CD_15 CD_16 CD_17 CD_18 CD_19 CD_110; rename..." then the blank between the SET statement and the first data set was missing.

The reason for this is that the cats() function as used in the call execute code bit "execute(cats('data CCD_',put(j,8.),'; set ', names ,'; rename COL1=C;'));" removes all the leading and trailing blanks when concatenating the string and therefore the trailing blank in '; set  ' gets removed. That's why it's not working.

I find it often easier to construct the command outside of the call execute() block and then pass in the whole command string as a single variable. This allows you to "putlog" your variable first so you can easily check what you want call execute() to process for you without having to run it.

Code like below should do (untested):

data want;

  length cmd $ 300;

  do j=1 to 11;

    cmd='';

    do i = 1 to 10;

      cmd = catx(' ',cmd,cats("CD_",J,I));

    end;

    cmd='data CCD_'||put(j,8.)||'; set '||strip(names)||'; rename COL1=C; run;';

    putlog cmd;

    call execute(cmd);

  end;

run;

Above shows you how you could create the command. You will now of course have to work a bit more in order to get what you've described in your initial post. This code only creates target data set "CCD_10".

LinusH
Tourmaline | Level 20

RTM = read the manual.

CATS is trimming all strings prior to concatenation.  That's why you get the syntax error from your call execute.

Starting to feel that you want/need help to do the whole application. Perhaps time for you to try to solve your task, otherwise hire the muscle to do it.

Data never sleeps

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 20 replies
  • 2335 views
  • 1 like
  • 5 in conversation