02-25-2016 02:03 AM
input start $ 1-2 label $50. ;
am new to formats how can i create a macro with input dataset as parameter & create format from the dataset details! help ?
02-25-2016 02:28 AM
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;
02-25-2016 02:36 AM
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;
02-25-2016 02:46 AM
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.
02-25-2016 02:50 AM
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?
02-25-2016 02:56 AM
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.
02-25-2016 09:48 AM
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.