DATA Step, Macro, Functions and more

Var Arrays

Reply
Contributor
Posts: 37

Var Arrays

I have a list of cities that I want to put into an array from a data set:

data test_array;

set city;

array a(*) city;

do i = 1 to dim(a);

put a(i) = city;

end;

run;

proc print no obs data=test;

run;

code above does not work

I would like the out put to look like this instead of ...

Baltimore      Washington      Hanover

Contributor
Posts: 37

Var Arrays

sorry output to look like this

Baltimore      Washington   Hanover

instead of this

baltimore

washington

hanover

Super User
Posts: 17,963

Var Arrays

For the entire dataset?

You can do a proc transpose, but I'm guessing there's some other criteria as well?

Contributor
Posts: 23

Var Arrays

Hello Mick_g,

Here is some code to get you started on transforming data from long to wide.

data city (keep = city);

  set sashelp.zipcode (firstobs=2000 obs=2010);

run;

data test_array (drop = i city);

array a

  • $25. cty1-cty11;

    do i = 1 to dim(a);

    set city;

    a(i) = city;

    end;

    run;

    Rich

    Super User
    Posts: 9,691

    Var Arrays

    using @ and / operator.

    data _null_;
     set sashelp.class;
      put name @;
     if mod(_n_,3)=0 then put /;
    run;
    
    
    
    
    
    Alfred Alice Barbara
    
    Carol Henry James
    
    Jane Janet Jeffrey
    
    John Joyce Judy
    
    Louise Mary Philip
    
    Robert Ronald Thomas
    
    
    

    Ksharp

    Ask a Question
    Discussion stats
    • 4 replies
    • 163 views
    • 7 likes
    • 4 in conversation