Dear community, I am a SAS beginner and new on SAS communities but I am currently looking for a programming code I could not find a solution, neither on the internet nor here in SAS communities. Probably it is since I cannot phrase it any better, but I hope you can help me out with. Thank you in advance! Let us assume I have a couple of data sets, e.g. one is called DS01, another DS02, etc. The number of data sets varies and should play a role in the code. However the names of the datasets should be independent and can be e.g. AB01, XX05, GHF912 or whatever. Each data set has a couple of variables, each a different number of variables e.g. DS01 has got variables VAR01, VAR02, VAR03, VAR4 then DS02 has got VAR01, VAR02, VAR05, VAR06 etc. The same applies here: The total number and names of variables differ. It is just for clarification. Now to my point: Some (not all) variables across datasets are numerics and have certain formats. Let us assume the variables have the same format names as their variable names e.g. VAR03 has format VAR03. and VAR05 has got VAR05., VAR06 has got VAR06. However, also the format names can be different than in my examples. The remaining variables have either simple numeric formats e.g. BEST32. or any text formats e.g. $2. or $40. I am only interested in those that have defined formats. My question is: I want to have a macro/macros that look up each dataset for variables that have these defined formats. Each time when there is a variable detected that has such a defined format the variable should be copied in the same dataset but with a slightly different naming e.g. "LBL" at the ending ie. VAR03 is copied to VAR03LBL, VAR05 copied to VAR05LBL etc. The original variable should remain unchanged and the copied should have the labelled content of the formatted variable ie. If VAR03=1 (1=Yes, 0=No) Then VAR03LBL=Yes, If VAR03=0 Then VAR03LBL=No etc. In the end I want to have each formatted variable as a pair: one contains the value, the other is the label. Best would be when the copied variable is put directly next to the formatted variable ie. VAR03, VAR03LBL, VAR04 etc., but that is not a requirement. All should be done independently from how many datasets or variables are available, and independently from namings. I want to refer as less variables as necessary, the macro(s) should do the work almost "alone". I found a lot on do loops using %sysfunc e.g. %sysfunc(varfmt(...)), but no paper or solution fit my question. Even if I am just a beginner, I am willing to learn it. Please help me! Best regards, Schueppi
... View more