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_var | Range | Current Count | Current % | Previous Count | Previous % | % Change | Previous Count |
M00_ACCT_BALANCE_AM | ._0 | 313,313,113 | 36.16% | . | 33.97% | 2.19% | 2,323,333,131 |
M00_ACCT_BALANCE_AM | 1_100 | 313,313,113 | 5.58% | . | 33.97% | 2.19% | 2,323,333,131 |
And I need this:
month_var | Range | Current Count | Current % | Previous Count | Previous % | % Change |
M00_ACCT_BALANCE_AM | ._0 | 313,313,113 | 36.16% | 2,323,333,131 | 33.97% | 2.19% |
M00_ACCT_BALANCE_AM | 1_100 | 313,313,113 | 5.58% | 2,323,333,131 | 33.97% | 2.19% |
M00_ACCT_BALANCE_AM | 101_500 | 313,313,113 | 12.15% | 2,323,333,131 | 33.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 ;
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.
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.
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
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.
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.