Help using Base SAS procedures

How can I create a variable using Proc import/sort and not transpose?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How can I create a variable using Proc import/sort and not transpose?

I was wondering if someone could help me with a simple but yet complex task that's driving me nuts.  Thanks.

My data set in excel

dogcatmicecamelpigeoncowgoatfishhorsedonkeymonkeylionrat
970.2525340.572243184345633122315440.69

I want to create two variables 'animals' and 'weight' to match each animal in columns with respective weight without modifying the data. Just by using proc import and or proc sort.

proc import datafile='E:\Copy of final examination.xls' out=Animals dbms=xls replace;sheet=animals;run;


Accepted Solutions
Solution
‎05-17-2013 10:43 PM
Respected Advisor
Posts: 4,651

Re: How can I create a variable using Proc import/sort and not transpose?

The trick is to use function vname to get the variable names and the _NUMERIC_ variable list to populate an array :

data want;

set animals;

array v{*} _NUMERIC_;

do i = 1 to dim(v);

     animal = vname(v{i});

     weight = v{i};

     output;

     end;

keep animal weight;

run;

PG

PG

View solution in original post


All Replies
Solution
‎05-17-2013 10:43 PM
Respected Advisor
Posts: 4,651

Re: How can I create a variable using Proc import/sort and not transpose?

The trick is to use function vname to get the variable names and the _NUMERIC_ variable list to populate an array :

data want;

set animals;

array v{*} _NUMERIC_;

do i = 1 to dim(v);

     animal = vname(v{i});

     weight = v{i};

     output;

     end;

keep animal weight;

run;

PG

PG
Occasional Contributor
Posts: 8

Re: How can I create a variable using Proc import/sort and not transpose?

Wow thank you for your help that's exactly what I was trying to figure out!

☑ This topic is SOLVED.

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

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