DATA Step, Macro, Functions and more

Create dataset from array

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 124
Accepted Solution

Create dataset from array

Greetings all.  I need to create a 6500 unique account numbers for testing, 'ACCTNO0001' through 'ACCTNO6500'.  I'm putting them into a one dimension array, but I can't figure out how to write the array to a dataset.  I thought the write_array function would work, but I keep getting error message below.  Is there a way to do this?  All the example I found showed 2 dimension arrays, so maybe that is the problem?  Thank you.

data _null_ ;

    array accts[6500] $ ;

    do i = 1 to 6500 ;

        x = cat("ACCTNO",put(i,z4.)) ;

        accts(i) = x ;

    end ;

    rc = write_array('work.accounts',accts) ;

run ; quit ;

ERROR 68-185: The function WRITE_ARRAY is unknown, or cannot be accessed.

ERROR: Illegal reference to the array accts.

Greg


Accepted Solutions
Solution
‎02-06-2014 04:57 PM
PROC Star
Posts: 7,363

Re: Create dataset from array

Not really sure what you are trying to end up with.  Do you want all of the data on one record or one each on 6500 records?  The following would do the latter:

data work.accounts;

   do _n_=1 to 6500;

     ACCTNO=put(_n_,z4.);

      output;

   end ;

run;


View solution in original post


All Replies
Solution
‎02-06-2014 04:57 PM
PROC Star
Posts: 7,363

Re: Create dataset from array

Not really sure what you are trying to end up with.  Do you want all of the data on one record or one each on 6500 records?  The following would do the latter:

data work.accounts;

   do _n_=1 to 6500;

     ACCTNO=put(_n_,z4.);

      output;

   end ;

run;


Frequent Contributor
Posts: 124

Re: Create dataset from array

Thank you Arthur, that is exactly what I wanted to do.  I did not realize I could create a dataset on the fly using a loop.  As usual, I made it harder than it needed to be.

Greg

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 214 views
  • 0 likes
  • 2 in conversation