BookmarkSubscribeRSS Feed
mick_g
Calcite | Level 5

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

4 REPLIES 4
mick_g
Calcite | Level 5

sorry output to look like this

Baltimore      Washington   Hanover

instead of this

baltimore

washington

hanover

Reeza
Super User

For the entire dataset?

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

rtritz
Calcite | Level 5

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

    Ksharp
    Super User

    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

    hackathon24-white-horiz.png

    The 2025 SAS Hackathon has begun!

    It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

    Latest Updates

    How to Concatenate Values

    Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

    Find more tutorials on the SAS Users YouTube channel.

    SAS Training: Just a Click Away

     Ready to level-up your skills? Choose your own adventure.

    Browse our catalog!

    Discussion stats
    • 4 replies
    • 1556 views
    • 7 likes
    • 4 in conversation