keep order of data set

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

keep order of data set

Hi Team,

 

I want something very easy.

I want to mantain the same order of the variables of this dataset.

 

 

set output.&cons ;

 

 

I tried with retain and using keep statement and this does not mantain the same order of the variable names.

I read on the forums and they suggested to use Retain and Format

 

 

options validvarname=any;
data testa (drop=r1 r2 "Range Start"n "Range End"n) ;
format    
month_var $char32.
Range $char24.
"Current Count"n comma15.
"Current %"n percent12.2
"Previous Count"n comma15.
"Previous %"n percent12.2
"% Change"n percent12.2
; 
set output.&cons ;
r1=put(input("Range Start"n,15.),comma12.);
r2=put("Range End"n,comma15.);
Range=CATX('_',r1,r2);
;
run;
NOTE: Variable 'Previous Count'n is uninitialized.

 

 

getting this like Output:

 

month_varRangeCurrent CountCurrent %Previous CountPrevious %% Change Previous Count
M00_ACCT_BALANCE_AM._0313,313,11336.16%.33.97%2.19%2,323,333,131
M00_ACCT_BALANCE_AM1_100313,313,1135.58%.33.97%2.19%2,323,333,131

 

 

And I need this:

 

month_varRangeCurrent CountCurrent % Previous CountPrevious %% Change
M00_ACCT_BALANCE_AM._0313,313,11336.16%2,323,333,13133.97%2.19%
M00_ACCT_BALANCE_AM1_100313,313,1135.58%2,323,333,13133.97%2.19%
M00_ACCT_BALANCE_AM101_500313,313,11312.15%2,323,333,13133.97%2.19%

 

My question are 2:

 

1. Why is reading twice the variable "Previous Count" ? One with expected output and another with missing values

2.  Is there an easy way to mantain the same order of the variable names of my dataset ?

set output.&cons ;

 

 


Accepted Solutions
Solution
‎02-24-2017 02:03 PM
Valued Guide
Posts: 797

Re: keep order of data set

[ Edited ]

Then just make sure your "set" statement precedes any statements referring to new variables.

 

The PDV (program data vector) will then have the original vars in original order on the left, and newly encountered vars to the right, in the order they are encountered by the sas compiler.

 

Edit:  Answer to 2nd question.  Your dataset probably already has a var named " Previous Count"n  (note the leading blank), but you are declaring another var "Previous Count"n   (no leading blank).  Two different variable names.

View solution in original post


All Replies
Solution
‎02-24-2017 02:03 PM
Valued Guide
Posts: 797

Re: keep order of data set

[ Edited ]

Then just make sure your "set" statement precedes any statements referring to new variables.

 

The PDV (program data vector) will then have the original vars in original order on the left, and newly encountered vars to the right, in the order they are encountered by the sas compiler.

 

Edit:  Answer to 2nd question.  Your dataset probably already has a var named " Previous Count"n  (note the leading blank), but you are declaring another var "Previous Count"n   (no leading blank).  Two different variable names.

Contributor
Posts: 42

Re: keep order of data set

Thanks Man!!

My variable Previous Count I don´t know why had leading spaces values,

" Previous Count"n comma15.

and it worked properly

 

Thanks again

☑ This topic is SOLVED.

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

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