DATA Step, Macro, Functions and more

base sas

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

base sas

Hi all i have data in vertical format i want it in horizontal format without using proc transpose with simple approch 

 

have.PNGwant.PNG


Accepted Solutions
Solution
a month ago
SAS Employee
Posts: 116

Re: base sas

Why not proc transpose? It is the right tool for the job.    You could easily use a data step that will be something like this. If you provided the data in a form I could copy, I could test the code, but since you didn't I'll leave it to you to fill in the details

 

data;

 set;

 by notsorted cust;

retain checking mortage saving credit_card;

if account = 'checking' then checking = balance;

... three more obvious if then assignments to make the other variables ...

if last.cust then output;

drop account balance;

run;

 

There are other ways, of course, to do this.

View solution in original post


All Replies
Solution
a month ago
SAS Employee
Posts: 116

Re: base sas

Why not proc transpose? It is the right tool for the job.    You could easily use a data step that will be something like this. If you provided the data in a form I could copy, I could test the code, but since you didn't I'll leave it to you to fill in the details

 

data;

 set;

 by notsorted cust;

retain checking mortage saving credit_card;

if account = 'checking' then checking = balance;

... three more obvious if then assignments to make the other variables ...

if last.cust then output;

drop account balance;

run;

 

There are other ways, of course, to do this.

Super User
Posts: 6,936

Re: base sas

You do that with proc transpose, period. Use the right tool for the task.

Anything else would involve a lot of meta-programming to make it flexible vis the values in account, and therefore be stupid.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

Re: base sas

I agree with you, but this is my institute question , that is why i posted .
Super User
Posts: 6,936

Re: base sas

You already got a blueprint from @WarrenKuhfeld, adapt it to your needs, but you will have to expand that code everytime a new value in account appears.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 173 views
  • 1 like
  • 3 in conversation