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

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    Register now!

    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.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

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