data details;
input start $ 1-2 label $50. ;
datalines;
1 AFGAN
2 MULTIPLE
3 OTHER
;
RUN;
am new to formats how can i create a macro with input dataset as parameter & create format from the dataset details! help ?
You just need two additional columns in your dataset:
data details;
input start $ 1-2 label $50.;
fmtname = 'xnational';
type = 'C';
datalines;
1 AFGAN
2 MULTIPLE
3 OTHER
;
run;
proc format library=work cntlin=details;
run;
data want;
nationality = put("1",$xnational.);
run;
Are you asking if you can use the FORMAT as a source for valid values for data cleaning?
No need for Macro.
data details;
input start $ 1-2 label $50. ;
fmtname='fmt';
type='n';
datalines;
1 AFGAN
2 MULTIPLE
3 OTHER
;
RUN;
proc format cntlin=details;run;
data _NULL_;
test=1; fmt=put(test,fmt.); putlog test= fmt=;
test=2; fmt=put(test,fmt.); putlog test= fmt=;
test=4; fmt=put(test,fmt.); putlog test= fmt=;
run;
No matter how big a dataset is, the code stays the same. NO need for a macro.
Unless you have other requirements that you did not mention.
What is the inds parameter in the macro? The dataset that contains the layout of the format, or the dataset that the format should be applied on?
Then you need more parameters. Which column(s) should which format be applied to?
In the end you may find that writing a macro that solves all cases will be more effort than simply writing the format assignments by hand.
Unfortunately, you have a difficult task. You will need to go back to the person who gave you the requirements and tell them that they have no idea what they are talking about.
If you look at output data sets based on a format, there are roughly 20 variables. That means you will need roughly 20 parameters on such a macro, depending on which features of a format you would like to utilize. There is no way that a single parameter can do that. If you can narrow down the features that are needed, you can reduce the number of parameters. But you have to start with a list of features.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.