我有一个名为weight
的字符串85.5
我想将其转换为数字85,5
,并使用SAS将逗号替换为小数分隔符。
到目前为止,我正在使用这种(凌乱)两步法
weight_num= (weight*1);
format weight_num COMMAX13.2;
如何以较少的方式实现这一目标?
答案 0 :(得分:1)
您的示例代码是更改变量类型的推荐方法。
另一种方法是(function($) {
$(document).ready(function () {
/*-------------------- EXPANDABLE PANELS ----------------------*/
var panelspeed = 500; //panel animate speed in milliseconds
var totalpanels = 6; //total number of collapsible panels
var defaultopenpanel = 1; //leave 0 for no panel open
var accordian = false; //set panels to behave like an accordian, with one panel only ever open at once
var panelheight = new Array();
var currentpanel = defaultopenpanel;
var iconheight = parseInt($('.icon-close-open').css('height'));
var highlightopen = true;
$('.nav a').click(function() {
$($(this).attr('href')).find('.expandable-panel-heading').click();
});
//Initialise collapsible panels
function panelinit() {
for (var i=1; i<=totalpanels; i++) {
panelheight[i] = parseInt($('#cp-'+i).find('.expandable-panel-content').css('height'));
$('#cp-'+i).find('.expandable-panel-content').css('margin-top', -panelheight[i]);
$('#cp-'+i).find('.icon-close-open').css('background-position', '0px -'+iconheight+'px');
$('#cp-'+i).find('.expandable-panel-content').css('margin-top', 0);
}
}
$('.expandable-panel-heading').click(function() {
var obj = $(this).next();
var objid = parseInt($(this).parent().attr('ID').substr(3,2));
currentpanel = objid;
if (accordian == true) {
resetpanels();
}
if (parseInt(obj.css('margin-top')) <= (panelheight[objid]*-1)) {
obj.clearQueue();
obj.stop();
obj.prev().find('.icon-close-open').css('background-position', '0px -'+iconheight+'px');
obj.animate({'margin-top':0}, panelspeed);
if (highlightopen == true) {
$('#cp-'+currentpanel + ' .expandable-panel-heading').addClass('header-active');
}
} else {
obj.clearQueue();
obj.stop();
obj.prev().find('.icon-close-open').css('background-position', '0px 0px');
obj.animate({'margin-top':(panelheight[objid]*-1)}, panelspeed);
if (highlightopen == true) {
$('#cp-'+currentpanel + ' .expandable-panel-heading').removeClass('header-active');
}
}
});
function resetpanels() {
for (var i=1; i<=totalpanels; i++) {
if (currentpanel != i) {
$('#cp-'+i).find('.icon-close-open').css('background-position', '0px 0px');
$('#cp-'+i).find('.expandable-panel-content').animate({'margin-top':-panelheight[i]}, panelspeed);
if (highlightopen == true) {
$('#cp-'+i + ' .expandable-panel-heading').removeClass('header-active');
}
}
}
}
//Uncomment these lines if the expandable panels are not a fixed width and need to resize
$( window ).resize(function() {
panelinit();
});
$(window).load(function() {
panelinit();
}); //END LOAD
}); //END READY
})(jQuery);
函数来替换。用逗号。如果您不打算对这些值进行任何计算,这只是一种很好的方法。
transtrn
答案 1 :(得分:1)
如果您只是想更改它以便逗号用于小数点而不是句点,那么为什么不使用简单的字符替换。您是否还想将千位分隔符从逗号更改为句点? TRANSLATE()
对此有好处。
weight = translate(weight,',.','.,');
如果您想将其转换为数字,请使用INPUT()
功能,而不是强制SAS为您转换。
weight_num = input(weight,comma32.);
然后,您可以将所需的任何格式附加到新的数字变量。